<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: mikestan</title>
    <description>The latest articles on DEV Community by mikestan (@zhangzhi45).</description>
    <link>https://dev.to/zhangzhi45</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4107136%2F008c2ce5-9d8e-4a10-af63-1b29a49a8f62.png</url>
      <title>DEV Community: mikestan</title>
      <link>https://dev.to/zhangzhi45</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zhangzhi45"/>
    <language>en</language>
    <item>
      <title>How to Style an HTML &lt;hr&gt;: A Clean, Copy-Paste CSS Pattern</title>
      <dc:creator>mikestan</dc:creator>
      <pubDate>Thu, 03 Sep 2026 03:07:22 +0000</pubDate>
      <link>https://dev.to/zhangzhi45/how-to-style-an-html-a-clean-copy-paste-css-pattern-4h8i</link>
      <guid>https://dev.to/zhangzhi45/how-to-style-an-html-a-clean-copy-paste-css-pattern-4h8i</guid>
      <description>&lt;p&gt;Most browsers render an HTML &lt;code&gt;&amp;lt;hr&amp;gt;&lt;/code&gt; as a horizontal rule, but the default styling is not always what you want in a real interface.&lt;/p&gt;

&lt;p&gt;A common first attempt is to change &lt;code&gt;height&lt;/code&gt; or &lt;code&gt;color&lt;/code&gt; and move on. That can leave the browser's default border in place, which is why a divider may look thicker, doubled, or different from the design you expected.&lt;/p&gt;

&lt;p&gt;Here is a small, reusable pattern that makes the result predictable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with a stable divider class
&lt;/h2&gt;

&lt;p&gt;Add this HTML wherever a thematic break between sections makes sense:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;hr&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"section-divider"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then add this CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;hr&lt;/span&gt;&lt;span class="nc"&gt;.section-divider&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;dashed&lt;/span&gt; &lt;span class="m"&gt;#ca8a04&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;60%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;42rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a centered, dashed divider that stays readable on both narrow and wide layouts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why this pattern works
&lt;/h2&gt;

&lt;p&gt;There are four important choices in that snippet:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;border: 0&lt;/code&gt; removes the browser's default border before you add your own style.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;border-top&lt;/code&gt; gives you one visible line to control.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;width&lt;/code&gt; and &lt;code&gt;max-width&lt;/code&gt; keep the divider from becoming excessively long.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;margin: 2rem auto&lt;/code&gt; adds vertical breathing room and centers the element.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The &lt;code&gt;hr&lt;/code&gt; element is also semantic. It represents a thematic break in content, such as a shift from one topic to another. That makes it a better choice than a random empty &lt;code&gt;div&lt;/code&gt; when the line actually separates ideas.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three useful variations
&lt;/h2&gt;

&lt;p&gt;Once the base pattern is in place, changing the appearance is straightforward.&lt;/p&gt;

&lt;h3&gt;
  
  
  A quiet solid divider
&lt;/h3&gt;

&lt;p&gt;Use this when the line should support the layout without attracting attention:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;hr&lt;/span&gt;&lt;span class="nc"&gt;.section-divider&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#cbd5e1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5rem&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  A dotted divider
&lt;/h3&gt;

&lt;p&gt;A dotted rule works well for lightweight notes, forms, or playful interfaces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;hr&lt;/span&gt;&lt;span class="nc"&gt;.section-divider&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="nb"&gt;dotted&lt;/span&gt; &lt;span class="m"&gt;#94a3b8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  A stronger double divider
&lt;/h3&gt;

&lt;p&gt;For an editorial section break, use a double border with enough thickness for the two lines to remain visible:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;hr&lt;/span&gt;&lt;span class="nc"&gt;.section-divider&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4px&lt;/span&gt; &lt;span class="nb"&gt;double&lt;/span&gt; &lt;span class="m"&gt;#475569&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;70%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2.5rem&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Two mistakes to avoid
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Styling &lt;code&gt;height&lt;/code&gt; without clearing the border
&lt;/h3&gt;

&lt;p&gt;This is the source of many unexpected divider styles:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Avoid relying on this alone */&lt;/span&gt;
&lt;span class="nt"&gt;hr&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#ca8a04&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some browser defaults can still contribute a border. Start by resetting the border, then choose either &lt;code&gt;border-top&lt;/code&gt; or a deliberate background-based design.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using old presentational attributes
&lt;/h3&gt;

&lt;p&gt;Attributes such as &lt;code&gt;size&lt;/code&gt; and &lt;code&gt;noshade&lt;/code&gt; are old HTML patterns. CSS gives you clearer, reusable control over color, spacing, width, and style.&lt;/p&gt;

&lt;h2&gt;
  
  
  When not to use &lt;code&gt;&amp;lt;hr&amp;gt;&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Use &lt;code&gt;&amp;lt;hr&amp;gt;&lt;/code&gt; when the line marks a real change of topic or section.&lt;/p&gt;

&lt;p&gt;If the line is only decorative—for example, a visual flourish inside a card or a component border—a styled &lt;code&gt;div&lt;/code&gt; or a pseudo-element may be a better fit. The markup should describe the meaning of the content, not only its appearance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try the styles before copying code
&lt;/h2&gt;

&lt;p&gt;If you want to experiment with the color, width, thickness, alignment, and line style before editing your stylesheet, try the &lt;a href="https://www.htmlpocket.com/tools/html-line-divider/" rel="noopener noreferrer"&gt;HTML Line Divider Generator&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/hr" rel="noopener noreferrer"&gt;MDN: The &lt;code&gt;&amp;lt;hr&amp;gt;&lt;/code&gt; element&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://html.spec.whatwg.org/multipage/grouping-content.html#the-hr-element" rel="noopener noreferrer"&gt;WHATWG HTML Standard: The &lt;code&gt;hr&lt;/code&gt; element&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
