Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a <hr /> element have a closing tag?

Tags:

html

xhtml

My colleague doesn't really know or understand html. Her job is to input information into the CMS and I've noticed she keeps closing her <hr /> tags like this <hr></hr>.

I've had a Google but I can't find anywhere that says this isn't allowed or could cause problems. I know it's supposed to be <hr /> but is it worth me telling her or is it unnecessary but valid markup?

NB The doctype for our website is XHTML 1.0 Transitional if that makes any difference.

EDIT

@Jeff had a good idea about validating. I used the following code and apparently this is valid XHTML 1.0 Transitional

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
    </head>
    <body>
        <hr></hr>
    </body>
</html>
like image 904
punkrockbuddyholly Avatar asked Jun 21 '11 15:06

punkrockbuddyholly


People also ask

Does HR have closing tag?

The HR element draws a horizontal rule. This is a block element and does not require a closing tag.

What does the HR /> tag produce?

The HTML <hr> tag is used for creating a horizontal line. This is also called Horizontal Rule in HTML.

What is the HR /> tag?

The <hr> tag defines a thematic break in an HTML page (e.g. a shift of topic). The <hr> element is most often displayed as a horizontal rule that is used to separate content (or define a change) in an HTML page.

Do the HTML tags BR and HR have a closing tag?

Do you close your <img>, <br> and <hr> tags? In HTML5 void elements are not required to be closed, that means <br> and <br /> are treated the same. Nevertheless i prefer to use the latest one to make clear I do not expend a closing tag.


1 Answers

OK, <hr></hr> is actually a valid XHTML 1.0, too.

So, for XHTML 1.0:

  • <hr /> is valid
  • <hr></hr> is valid
  • <hr> is not valid

... for HTML 4.0:

  • <hr /> is valid
  • <hr></hr> is not valid
  • <hr> is valid

therefore the best option is to use <hr />, which is always valid.

like image 58
Ruslan Avatar answered Oct 14 '22 14:10

Ruslan