{"id":19271,"date":"2017-12-04T16:15:34","date_gmt":"2017-12-04T14:15:34","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=19271"},"modified":"2018-01-08T14:09:36","modified_gmt":"2018-01-08T12:09:36","slug":"css-horizontal-line-styling-example","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/","title":{"rendered":"CSS Horizontal Line Styling Example"},"content":{"rendered":"<h2>1. Introduction<\/h2>\n<p>In any web page or blog post, it is usually a good practice to identify and divide elements and sections which are logically separate. You could use HTML elements like <code>div<\/code> for encapsulating multiple page elements, <code>ul<\/code> and <code>ol<\/code> for organizing lengthy text into a more readable list-based format, or simply use <code>hr<\/code> to create a horizontal line.<\/p>\n<p>The <code>hr<\/code> element, also known as the <em>Horizontal Rule<\/em>, can be styled using CSS just like other elements. Do make sure to have the Mozilla Firefox and Google Chrome browsers available with you to test the various aspects related to styling this element.<\/p>\n<p>Let&#8217;s now discuss the details. Do note that the link to download the complete source code is available at the end of this example.<br \/>\n[ulp id=&#8217;nAkUl5IbAjqlXSla&#8217;]<\/p>\n<h2>2. A simple usage example<\/h2>\n<p>Let&#8217;s quickly refresh our memory and look at a very simple scenario where an <code>hr<\/code> will come in handy. Create an HTML file and name it <code>example.html<\/code>. Copy and paste the below contents into it:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>example.html<\/em><\/span><\/p>\n<pre class=\"brush:html\">&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n&lt;head&gt;\r\n    &lt;meta charset=\"UTF-8\"&gt;\r\n    &lt;title&gt;CSS Horizontal Line Styling Example&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;h2&gt;Topic 1&lt;\/h2&gt;\r\n&lt;p&gt;This is content for topic 1&lt;\/p&gt;\r\n&lt;hr&gt;\r\n&lt;h2&gt;Topic 2&lt;\/h2&gt;\r\n&lt;p&gt;This is content for topic 2&lt;\/p&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>As of now, neither have we attached any stylesheet nor applied any styles. Save the file and open it in your browser. You should see something like this:<\/p>\n<figure id=\"attachment_19412\" aria-describedby=\"caption-attachment-19412\" style=\"width: 750px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/12\/hr_simple.jpg\"><img decoding=\"async\" class=\"wp-image-19412 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/12\/hr_simple.jpg\" alt=\"Fig. 1: A simple hr element\" width=\"750\" height=\"457\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/12\/hr_simple.jpg 750w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/12\/hr_simple-300x183.jpg 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><figcaption id=\"caption-attachment-19412\" class=\"wp-caption-text\">Fig. 1: A simple hr element<\/figcaption><\/figure>\n<p>Let&#8217;s proceed and attach a stylesheet to our page.<\/p>\n<h2>3. Style an hr element with CSS<\/h2>\n<p>Now that we have created a basic <code>hr<\/code>, let&#8217;s create our stylesheet which will control the look and feel for the element. In the same directory as <code>example.html<\/code>, create another file called <code>style.css<\/code> and paste the below code into it:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>style.css<\/em><\/span><\/p>\n<pre class=\"brush:css\">hr {\r\n\twidth: 200px;\r\n\tmargin-left: 0px;\r\n}\r\n<\/pre>\n<p>Open <code>example.html<\/code> and add the below highlighted line of code to attach the stylesheet to the HTML file. Here&#8217;s what the full HTML code should look like:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>example.html<\/em><\/span><\/p>\n<pre class=\"brush:html; highlight:[6]\">&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en\"&gt;\r\n&lt;head&gt;\r\n    &lt;meta charset=\"UTF-8\"&gt;\r\n    &lt;title&gt;CSS Horizontal Line Styling Example&lt;\/title&gt;\r\n    &lt;link rel=\"stylesheet\" type=\"text\/css\" href=\".\/style.css\"&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;h2&gt;Topic 1&lt;\/h2&gt;\r\n&lt;p&gt;This is content for topic 1&lt;\/p&gt;\r\n&lt;hr&gt;\r\n&lt;h2&gt;Topic 2&lt;\/h2&gt;\r\n&lt;p&gt;This is content for topic 2&lt;\/p&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>Make sure you have saved both <code>example.html<\/code> and <code>style.css<\/code>. Open <code>example.html<\/code> in your web browser to view the changes. The <code>hr<\/code> element should resemble the below:<\/p>\n<figure id=\"attachment_19392\" aria-describedby=\"caption-attachment-19392\" style=\"width: 522px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css.jpg\"><img decoding=\"async\" class=\"wp-image-19392 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css.jpg\" alt=\"Fig. 2: An hr element styled with CSS\" width=\"522\" height=\"440\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css.jpg 522w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css-300x253.jpg 300w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/><\/a><figcaption id=\"caption-attachment-19392\" class=\"wp-caption-text\">Fig. 2: An hr element styled with CSS<\/figcaption><\/figure>\n<p>We reduced the width of the <code>hr<\/code> element to <code>200px<\/code> and aligned it the left. Notice that we used the <code>margin-left<\/code> property to do the alignment. Another way to do the same is by using the <code>align<\/code> attribute within the <code>hr<\/code> tag. Since the horizontal rule element look can now be controlled with our stylesheet, let&#8217;s go ahead and spice it up a little.<\/p>\n<h2>4. Add colors<\/h2>\n<p>You can use the CSS <code>color<\/code> property to change the color of your line. Make the following highlighted changes to your CSS code:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>style.css<\/em><\/span><\/p>\n<pre class=\"brush:css; highlight:[4]\">hr {\r\n\twidth: 200px;\r\n\tmargin-left: 0px;\r\n\tcolor: blue;\r\n}\r\n<\/pre>\n<p>In the Mozilla Firefox browser, you should be able to see the change when you save the CSS file and refresh the\u00a0<code>example.html<\/code> page:<\/p>\n<figure id=\"attachment_19395\" aria-describedby=\"caption-attachment-19395\" style=\"width: 530px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_blue_firefox.jpg\"><img decoding=\"async\" class=\"wp-image-19395 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_blue_firefox.jpg\" alt=\"Fig. 3: An hr element with modified CSS color property in Mozilla Firefox\" width=\"530\" height=\"445\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_blue_firefox.jpg 530w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_blue_firefox-300x252.jpg 300w\" sizes=\"(max-width: 530px) 100vw, 530px\" \/><\/a><figcaption id=\"caption-attachment-19395\" class=\"wp-caption-text\">Fig. 3: An hr element with modified CSS color property in Mozilla Firefox<\/figcaption><\/figure>\n<p>However, if you open the same page in Google Chrome, it still appears as a plain old line:<\/p>\n<figure id=\"attachment_19393\" aria-describedby=\"caption-attachment-19393\" style=\"width: 372px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_blue_chrome_notworking.jpg\"><img decoding=\"async\" class=\"wp-image-19393 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_blue_chrome_notworking.jpg\" alt=\"Fig. 4: Google Chrome does not render the modified CSS color property for the hr element correctly\" width=\"372\" height=\"464\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_blue_chrome_notworking.jpg 372w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_blue_chrome_notworking-241x300.jpg 241w\" sizes=\"(max-width: 372px) 100vw, 372px\" \/><\/a><figcaption id=\"caption-attachment-19393\" class=\"wp-caption-text\">Fig. 4: Google Chrome does not render the modified CSS color property for the hr element correctly<\/figcaption><\/figure>\n<p>To overcome this, apply another CSS property <code>background-color<\/code>, with the same value as the previously applied color property. It should also be noted that some browsers tend to display a default <code>1px<\/code> border around <code>hr<\/code> elements. To ensure a consistent look across browsers, you should explicitly specify the <code>border<\/code> and <code>height<\/code> properties together.<\/p>\n<p>Let&#8217;s update our stylesheet accordingly:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>style.css<\/em><\/span><\/p>\n<pre class=\"brush:css; highlight:[5,6,7]\">hr {\r\n\twidth: 200px;\r\n\tmargin-left: 0px;\r\n\tcolor: blue;\r\n\tbackground-color: blue;\r\n\tborder: 0px;\r\n\theight: 1px;\r\n}\r\n<\/pre>\n<p>Refresh the <code>example.html<\/code> in both Mozilla Firefox and Google Chrome &#8211; the results should now be identical. The element now renders correctly on Google Chrome, as shown below:<\/p>\n<figure id=\"attachment_19394\" aria-describedby=\"caption-attachment-19394\" style=\"width: 372px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_blue_chrome_working.jpg\"><img decoding=\"async\" class=\"wp-image-19394 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_blue_chrome_working.jpg\" alt=\"Fig. 5: Additional CSS properties ensure a more consistent look across browsers\" width=\"372\" height=\"441\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_blue_chrome_working.jpg 372w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_blue_chrome_working-253x300.jpg 253w\" sizes=\"(max-width: 372px) 100vw, 372px\" \/><\/a><figcaption id=\"caption-attachment-19394\" class=\"wp-caption-text\">Fig. 5: Additional CSS properties ensure a more consistent look across browsers<\/figcaption><\/figure>\n<p>Now that we know how to display the styled <code>hr<\/code> element across browsers in a more consistent way, let&#8217;s look at more ways to decorate it.<\/p>\n<h2>5. Use a background image<\/h2>\n<p>You can even use an image and apply it as a background. For this example, obtain any image and place it in the same directory as your source files &#8211; we have named it <code>image.jpg<\/code>, but you can call it anything as long as you use the correct URL in the CSS. Modify your stylesheet as below:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>style.css<\/em><\/span><\/p>\n<pre class=\"brush:css; highlight:[8]\">hr {\r\n\twidth: 200px;\r\n\tmargin-left: 0px;\r\n\tcolor: blue;\r\n\tbackground-color: blue;\r\n\tborder: 0px;\r\n\theight: 1px;\r\n\tbackground: #fff url(image.jpg) scroll center;\r\n}\r\n<\/pre>\n<p>Here&#8217;s what it looks like in a browser:<\/p>\n<figure id=\"attachment_19391\" aria-describedby=\"caption-attachment-19391\" style=\"width: 531px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_bg_image.jpg\"><img decoding=\"async\" class=\"wp-image-19391 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_bg_image.jpg\" alt=\"Fig. 6: Style the hr element with a background image\" width=\"531\" height=\"458\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_bg_image.jpg 531w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_bg_image-300x259.jpg 300w\" sizes=\"(max-width: 531px) 100vw, 531px\" \/><\/a><figcaption id=\"caption-attachment-19391\" class=\"wp-caption-text\">Fig. 6: Style the hr element with a background image<\/figcaption><\/figure>\n<p>Of course, the amount of the image that is visible depends on the <code>height<\/code> and <code>width<\/code> properties of the <code>hr<\/code> element &#8211; you can play around with it to suit your preferences.<\/p>\n<h2>6. Five more creative styles<\/h2>\n<p>Here are 5 creative <code>hr<\/code> styling ideas you can use in your own code. The highlighted lines in the code block for each style represent the change from our original CSS code.<\/p>\n<h3>6.1 Style 1<\/h3>\n<p>Below you can find the CSS code:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>style.css<\/em><\/span><\/p>\n<pre class=\"brush:css; highlight:[8]\">hr {\r\n\twidth: 200px;\r\n\tmargin-left: 0px;\r\n\tcolor: blue;\r\n\tbackground-color: blue;\r\n\tborder: 0px;\r\n\theight: 1px;\r\n\tbackground-image: linear-gradient(to right, #ccc, #333, #ccc);\r\n}\r\n<\/pre>\n<p>This is the result in the Browser:<\/p>\n<figure id=\"attachment_19396\" aria-describedby=\"caption-attachment-19396\" style=\"width: 530px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style1.jpg\"><img decoding=\"async\" class=\"wp-image-19396 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style1.jpg\" alt=\"Fig. 7: Creative CSS style 1 - gradient effects\" width=\"530\" height=\"432\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style1.jpg 530w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style1-300x245.jpg 300w\" sizes=\"(max-width: 530px) 100vw, 530px\" \/><\/a><figcaption id=\"caption-attachment-19396\" class=\"wp-caption-text\">Fig. 7: Creative CSS style 1 &#8211; gradient effects<\/figcaption><\/figure>\n<h3>6.2 Style 2<\/h3>\n<p>Below you can find the CSS code:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>style.css<\/em><\/span><\/p>\n<pre class=\"brush:css; highlight:[4,5,8]\">hr {\r\n\twidth: 200px;\r\n\tmargin-left: 0px;\r\n\tcolor: gray;\r\n\tbackground-color: gray;\r\n\tborder: 0px;\r\n\theight: 1px;\r\n\tborder-bottom: 2px dashed #222;\r\n}\r\n<\/pre>\n<p>This is the result in the Browser:<\/p>\n<figure id=\"attachment_19397\" aria-describedby=\"caption-attachment-19397\" style=\"width: 532px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style2.jpg\"><img decoding=\"async\" class=\"wp-image-19397 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style2.jpg\" alt=\"Fig. 8: Creative CSS style 2 - dashed line with 2 colors\" width=\"532\" height=\"415\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style2.jpg 532w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style2-300x234.jpg 300w\" sizes=\"(max-width: 532px) 100vw, 532px\" \/><\/a><figcaption id=\"caption-attachment-19397\" class=\"wp-caption-text\">Fig. 8: Creative CSS style 2 &#8211; dashed line with 2 colors<\/figcaption><\/figure>\n<h3>6.3 Style 3<\/h3>\n<p>Below you can find the CSS code:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>style.css<\/em><\/span><\/p>\n<pre class=\"brush:css; highlight:[4,5,7,8]\">hr {\r\n\twidth: 200px;\r\n\tmargin-left: 0px;\r\n\tcolor: white;\r\n\tbackground-color: white;\r\n\tborder: 0px;\r\n\theight: 10px;\r\n\tbox-shadow: inset 0 12px 12px -12px rgba(0, 0, 0, 0.5);\r\n}\r\n<\/pre>\n<p>This is the result in the Browser:<\/p>\n<figure id=\"attachment_19398\" aria-describedby=\"caption-attachment-19398\" style=\"width: 531px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style3.jpg\"><img decoding=\"async\" class=\"wp-image-19398 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style3.jpg\" alt=\"Fig. 9: Creative CSS style 3 - drop shadow effect\" width=\"531\" height=\"423\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style3.jpg 531w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style3-300x239.jpg 300w\" sizes=\"(max-width: 531px) 100vw, 531px\" \/><\/a><figcaption id=\"caption-attachment-19398\" class=\"wp-caption-text\">Fig. 9: Creative CSS style 3 &#8211; drop shadow effect<\/figcaption><\/figure>\n<h3>6.4 Style 4<\/h3>\n<p>Below you can find the CSS code:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>style.css<\/em><\/span><\/p>\n<pre class=\"brush:css; highlight:[4,5,7,8,10,11,12]\">hr {\r\n    width: 200px;\r\n    margin-left: 0px;\r\n    color: white;\r\n    background-color: white;\r\n    border: 0px;\r\n    height: 0px;\r\n    box-shadow: 0 0 5px 2px gray;\r\n}\r\nhr:after {\r\n    content: \"\\00a0\";  \/* prevents margin collapse *\/\r\n}\r\n<\/pre>\n<p>This is the result in the Browser:<\/p>\n<figure id=\"attachment_19399\" aria-describedby=\"caption-attachment-19399\" style=\"width: 532px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style4.jpg\"><img decoding=\"async\" class=\"wp-image-19399 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style4.jpg\" alt=\"Fig. 10: Creative CSS style 4 - blur effect\" width=\"532\" height=\"421\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style4.jpg 532w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style4-300x237.jpg 300w\" sizes=\"(max-width: 532px) 100vw, 532px\" \/><\/a><figcaption id=\"caption-attachment-19399\" class=\"wp-caption-text\">Fig. 10: Creative CSS style 4 &#8211; blur effect<\/figcaption><\/figure>\n<h3>6.5 Style 5<\/h3>\n<p>Below you can find the CSS code:<\/p>\n<p><span style=\"text-decoration: underline;\"><em>style.css<\/em><\/span><\/p>\n<pre class=\"brush:css; highlight:[4,5,7,8,10,11,12,13,14,15,16,17,18,19,20]\">hr {\r\n    width: 200px;\r\n    margin-left: 0px;\r\n    color: white;\r\n    background-color: white;\r\n    border: 0px;\r\n    height: 0px;\r\n    border-top: 1px dashed gray;\r\n}\r\nhr:after {\r\n    content: '\\002702';\r\n    display: inline-block;\r\n    position: relative;\r\n    top: -13px;\r\n    left: 20px;\r\n    padding: 0 2px;\r\n    background: white;\r\n    color: gray;\r\n    font-size: 15px;\r\n}\r\n<\/pre>\n<p>This is the result in the Browser:<\/p>\n<figure id=\"attachment_19400\" aria-describedby=\"caption-attachment-19400\" style=\"width: 532px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style5.jpg\"><img decoding=\"async\" class=\"wp-image-19400 size-full\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style5.jpg\" alt=\"Fig. 11: Creative CSS style 5 - scissor effect, cutting a dashed (perforated) line\" width=\"532\" height=\"404\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style5.jpg 532w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/hr_css_style5-300x228.jpg 300w\" sizes=\"(max-width: 532px) 100vw, 532px\" \/><\/a><figcaption id=\"caption-attachment-19400\" class=\"wp-caption-text\">Fig. 11: Creative CSS style 5 &#8211; scissor effect, cutting a dashed (perforated) line<\/figcaption><\/figure>\n<p>You can use the above CSS styles directly or customize them further to build even more interesting styles.<\/p>\n<h2>7. Download the Source Code<\/h2>\n<p>This was an example on styling the <code>hr<\/code> element in an HTML page.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2017\/11\/CSSHorizontalLineStylingExample.zip\"><strong>CSSHorizontalLineStylingExample.zip<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction In any web page or blog post, it is usually a good practice to identify and divide elements and sections which are logically separate. You could use HTML elements like div for encapsulating multiple page elements, ul and ol for organizing lengthy text into a more readable list-based format, or simply use hr &hellip;<\/p>\n","protected":false},"author":1661,"featured_media":917,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[236,114,501,502,503],"class_list":["post-19271","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css","tag-css","tag-css3","tag-horizontal-line","tag-horizontal-rule","tag-hr"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>CSS Horizontal Line Styling Example - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"1. Introduction In any web page or blog post, it is usually a good practice to identify and divide elements and sections which are logically separate. You\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"CSS Horizontal Line Styling Example - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"1. Introduction In any web page or blog post, it is usually a good practice to identify and divide elements and sections which are logically separate. You\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/JensonJoseOnline\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-12-04T14:15:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-08T12:09:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Jenson Jose\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JoseJenson\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jenson Jose\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/\"},\"author\":{\"name\":\"Jenson Jose\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/13448ace6851dad5ce8a8990bee47f0e\"},\"headline\":\"CSS Horizontal Line Styling Example\",\"datePublished\":\"2017-12-04T14:15:34+00:00\",\"dateModified\":\"2018-01-08T12:09:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/\"},\"wordCount\":989,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg\",\"keywords\":[\"CSS\",\"css3\",\"horizontal line\",\"horizontal rule\",\"hr\"],\"articleSection\":[\"CSS\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/\",\"name\":\"CSS Horizontal Line Styling Example - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg\",\"datePublished\":\"2017-12-04T14:15:34+00:00\",\"dateModified\":\"2018-01-08T12:09:36+00:00\",\"description\":\"1. Introduction In any web page or blog post, it is usually a good practice to identify and divide elements and sections which are logically separate. You\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CSS\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/css\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"CSS Horizontal Line Styling Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/13448ace6851dad5ce8a8990bee47f0e\",\"name\":\"Jenson Jose\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a00e4452e1e7b6c934a3df74d3174d17a51a6457119f9a36bdf48012e62fa29e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a00e4452e1e7b6c934a3df74d3174d17a51a6457119f9a36bdf48012e62fa29e?s=96&d=mm&r=g\",\"caption\":\"Jenson Jose\"},\"description\":\"Jenson currently works as a Lead Developer on various network automation projects, in one of the leading telecom MNCs. In his spare time, he enjoys reading fiction and gaming.\",\"sameAs\":[\"https:\/\/www.jensonjose.com\",\"https:\/\/www.facebook.com\/JensonJoseOnline\/\",\"https:\/\/x.com\/JoseJenson\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/jenson-jose\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"CSS Horizontal Line Styling Example - Web Code Geeks - 2026","description":"1. Introduction In any web page or blog post, it is usually a good practice to identify and divide elements and sections which are logically separate. You","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/","og_locale":"en_US","og_type":"article","og_title":"CSS Horizontal Line Styling Example - Web Code Geeks - 2026","og_description":"1. Introduction In any web page or blog post, it is usually a good practice to identify and divide elements and sections which are logically separate. You","og_url":"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"https:\/\/www.facebook.com\/JensonJoseOnline\/","article_published_time":"2017-12-04T14:15:34+00:00","article_modified_time":"2018-01-08T12:09:36+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg","type":"image\/jpeg"}],"author":"Jenson Jose","twitter_card":"summary_large_image","twitter_creator":"@JoseJenson","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Jenson Jose","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/"},"author":{"name":"Jenson Jose","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/13448ace6851dad5ce8a8990bee47f0e"},"headline":"CSS Horizontal Line Styling Example","datePublished":"2017-12-04T14:15:34+00:00","dateModified":"2018-01-08T12:09:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/"},"wordCount":989,"commentCount":5,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg","keywords":["CSS","css3","horizontal line","horizontal rule","hr"],"articleSection":["CSS"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/","url":"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/","name":"CSS Horizontal Line Styling Example - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg","datePublished":"2017-12-04T14:15:34+00:00","dateModified":"2018-01-08T12:09:36+00:00","description":"1. Introduction In any web page or blog post, it is usually a good practice to identify and divide elements and sections which are logically separate. You","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/css3-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/css\/css-horizontal-line-styling-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"CSS","item":"https:\/\/www.webcodegeeks.com\/category\/css\/"},{"@type":"ListItem","position":3,"name":"CSS Horizontal Line Styling Example"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/13448ace6851dad5ce8a8990bee47f0e","name":"Jenson Jose","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a00e4452e1e7b6c934a3df74d3174d17a51a6457119f9a36bdf48012e62fa29e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a00e4452e1e7b6c934a3df74d3174d17a51a6457119f9a36bdf48012e62fa29e?s=96&d=mm&r=g","caption":"Jenson Jose"},"description":"Jenson currently works as a Lead Developer on various network automation projects, in one of the leading telecom MNCs. In his spare time, he enjoys reading fiction and gaming.","sameAs":["https:\/\/www.jensonjose.com","https:\/\/www.facebook.com\/JensonJoseOnline\/","https:\/\/x.com\/JoseJenson"],"url":"https:\/\/www.webcodegeeks.com\/author\/jenson-jose\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/19271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/1661"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=19271"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/19271\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/917"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=19271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=19271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=19271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}