Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to horizontal rule tag `<hr>` working in html5

I am currently working on some html for a calendar (in html5), and I am trying to add in a coloured horizontal line. I have been using the horizontal rule tag <hr> but I'm struggling to get most of the attributes to work at all.

This is what I want:

<hr color="purple" align="left" width="120%" size="6">

I read that some attributes don't work in html5... and the only one that is working is the width tag. None of the others are doing anything!

How can I get this to work? Is there a better way to approach this?

like image 590
Ruth Young Avatar asked Feb 14 '17 13:02

Ruth Young


People also ask

What can I use instead of HR in HTML?

The width attribute on the hr element is obsolete. Use CSS instead. The noshade attribute on the hr element is obsolete. Use CSS instead.

How do I draw a horizontal line in CSS without HR?

Its simple to add a horizontal line in your markup, just add: <hr>. Browsers draw a line across the entire width of the container, which can be the entire body or a child element.

What is the only HTML tag used for horizontal rule?

Definition and Usage 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.


3 Answers

Use CSS rules

hr.someClass {
  background-color: purple;
  width: 120%;
  height: 12px;
  border-top: 1px solid black
}
<hr class="someClass">
like image 97
Satpal Avatar answered Sep 19 '22 11:09

Satpal


You could add a div with a border-top, as below:

<div style="border-top: 6px solid purple"></div>

With external styles (which is always better):

.horizontal-rule {
  border-top: 6px solid purple;
}
<div class="horizontal-rule"></div>
like image 45
CalvT Avatar answered Sep 18 '22 11:09

CalvT


In HTML 4.01, the <hr> tag represents a horizontal rule. In HTML5, the <hr> tag defines a thematic break. Also attributes like align, size and width are not supported in HTML5.

The proper alternative to this is defining a div as:

HTML

<div class="hr"></div>

CSS

.hr {
    border-top: 6px solid purple;
    width: 120%;
}
like image 23
Tariq B. Avatar answered Sep 22 '22 11:09

Tariq B.