How TO - Style HR [Horizontal Ruler/Line]
Learn how to style an hr element with CSS.
Horizontal Line
You can use the border
property to style a hr
element:
Example
/* Red border */
hr.new1 {
border-top: 1px solid red;
}
/* Dashed red border */
hr.new2 {
border-top: 1px dashed red;
}
/* Dotted red border */
hr.new3 {
border-top: 1px
dotted red;
}
/* Thick red border */
hr.new4 {
border: 1px solid red;
}
/* Large rounded green border */
hr.new5 {
border: 10px solid green;
border-radius: 5px;
}
Try it Yourself »
Related Pages
The HTML hr tag.
Example
Use the tag to define thematic changes in the content:
The Main Languages of the Web
HTML is the standard markup language for creating Web pages. HTML describes the structure of a Web page, and consists of a series of elements. HTML elements tell the browser how to display the content.
CSS is a language that describes how HTML elements are to be displayed on screen, paper, or in other media. CSS saves a lot of work, because it can control the layout of multiple web pages all at once.
JavaScript is the programming language of HTML and the Web. JavaScript can change HTML content and attribute values. JavaScript can change CSS. JavaScript can hide and show HTML elements, and more.
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The tag defines a thematic break in an HTML page [e.g. a shift of topic].
The element is most often displayed as a horizontal rule that is used to separate content [or define a change] in an HTML page.
Browser Support
Yes | Yes | Yes | Yes | Yes |
Global Attributes
The tag also supports the Global Attributes in HTML.
Event Attributes
The tag also supports the Event Attributes in HTML.
More Examples
Example
Align a element [with CSS]:
Try it Yourself »
Example
A noshaded [with CSS]:
Try it Yourself »
Example
Set the height of a element [with CSS]:
Try it Yourself »
Example
Set the width of a element [with CSS]:
Try it Yourself »
Related Pages
HTML DOM reference: HR Object
Default CSS Settings
Most browsers will display the element with the following default values:
Example
hr {
display: block;
margin-top: 0.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border-width: 1px;
}
Try it Yourself »
The Historically, this has been presented as a horizontal rule or line. While it may still be displayed as a horizontal rule in visual browsers, this element is now defined in semantic terms, rather than presentational terms, so if you wish to draw a horizontal line, you should do so using appropriate CSS. This element's attributes include the global attributes. Sets the alignment of the rule on the page. If no value is specified, the default value is Sets the color of the rule through color name or hexadecimal value. Sets the rule to have no shading. Sets the height, in pixels, of the rule. Sets the length of the rule on the page through a pixel
or percentage value. HTML element represents a thematic break between paragraph-level elements: for example, a change of scene in a story, or a shift of topic within a section.
Try
it
Attributes
align
Deprecated Non-standardleft
.color
Non-standard Deprecatednoshade
Deprecated Non-standardsize
Deprecated
Non-standardwidth
Deprecated Non-standardExample
HTML
This is the first paragraph of text.
This is the first paragraph of text.
This is the first paragraph of text.
This is the first paragraph of text.
This is the second paragraph of text.
This is the second paragraph of text.
This is the second paragraph of text.
This is the second paragraph of text.
Result
Specifications
HTML Standard # the-hr-element |
Browser compatibility
BCD tables only load in the browser