<?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: Youn</title>
    <description>The latest articles on DEV Community by Youn (@code1).</description>
    <link>https://dev.to/code1</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%2F4084193%2Ff0149310-cfee-4663-9685-04d3a079ba6f.png</url>
      <title>DEV Community: Youn</title>
      <link>https://dev.to/code1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/code1"/>
    <language>en</language>
    <item>
      <title>CSS @charset – Declaring Character Encoding for Stylesheets</title>
      <dc:creator>Youn</dc:creator>
      <pubDate>Tue, 06 Oct 2026 02:03:28 +0000</pubDate>
      <link>https://dev.to/code1/css-charset-declaring-character-encoding-for-stylesheets-35h2</link>
      <guid>https://dev.to/code1/css-charset-declaring-character-encoding-for-stylesheets-35h2</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;😄 This post is based on the content from &lt;a href="https://coding.courses/css-at-rule-charset/" rel="noopener noreferrer"&gt;coding.courses&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  @charset Rule
&lt;/h2&gt;

&lt;p&gt;The CSS @charset syntax rule is used to declare the character encoding of the stylesheet.&lt;br&gt;
It allows you to specify the desired character encoding for the stylesheet.&lt;br&gt;
It is used to explicitly specify the character encoding directly within the stylesheet, rather than relying on an external environment that, for any reason, might not match the stylesheet's encoding.&lt;br&gt;
It is particularly useful in environments where the default encoding of the HTML file or system is not set to the standard UTF-8, allowing you to independently set the stylesheet's internal encoding to UTF-8.&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="k"&gt;@charset&lt;/span&gt; &lt;span class="s1"&gt;"UTF-8"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Must be placed at the very beginning of the stylesheet */&lt;/span&gt;

&lt;span class="c"&gt;/* CSS rules should be placed after this rule */&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;18px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Syntax
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@charset&lt;/span&gt; &lt;span class="s1"&gt;"charset-name"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;charset-name represents the character encoding to be specified. It must be the name of a web-safe character encoding registered in the IANA registry. It must be separated from @charset by exactly one space, enclosed in double quotes ("), and immediately followed by a semicolon (;). It is case-insensitive.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The @charset rule must be placed at the very beginning of the stylesheet, and no characters, including whitespace, may appear before it.&lt;/li&gt;
&lt;li&gt;The @charset rule can only be used once in a stylesheet. If multiple @charset rules are used, only the first rule is applied.&lt;/li&gt;
&lt;li&gt;The @charset rule is specific to stylesheets and cannot be replaced by the charset attribute of the &amp;lt;link&amp;gt; tag in an HTML document.&lt;/li&gt;
&lt;li&gt;Stylesheets embedded in an HTML page, such as those within the &lt;a href="https://coding.courses/html-style-tag/" rel="noopener noreferrer"&gt;&amp;lt;style&amp;gt;&lt;/a&gt; tag or the style attribute, share the character encoding of the entire document. Therefore, even if the @charset rule is used within the &amp;lt;style&amp;gt; tag, the stylesheet still uses the character encoding of the entire document.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  # Valid and Invalid Syntax
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;----&lt;/span&gt; &lt;span class="nt"&gt;Valid&lt;/span&gt; &lt;span class="nt"&gt;Syntax&lt;/span&gt; &lt;span class="nt"&gt;----&lt;/span&gt;
&lt;span class="k"&gt;@charset&lt;/span&gt; &lt;span class="s1"&gt;"ISO-8859-1"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@charset&lt;/span&gt; &lt;span class="s1"&gt;"utf-8"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Same as "UTF-8": case-insensitive */&lt;/span&gt;

&lt;span class="nt"&gt;----&lt;/span&gt; &lt;span class="nt"&gt;Invalid&lt;/span&gt; &lt;span class="nt"&gt;Syntax&lt;/span&gt; &lt;span class="nt"&gt;----&lt;/span&gt;
&lt;span class="k"&gt;@charset&lt;/span&gt; &lt;span class="s2"&gt;'ISO-8859-1'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Enclosed in single quotes */&lt;/span&gt;
&lt;span class="k"&gt;@charset&lt;/span&gt; &lt;span class="n"&gt;ISO-8859-1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Not enclosed in double quotes */&lt;/span&gt;
&lt;span class="k"&gt;@charset&lt;/span&gt;    &lt;span class="s1"&gt;"ISO-8859-1"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* More than one whitespace character after @charset */&lt;/span&gt;
    &lt;span class="k"&gt;@charset&lt;/span&gt; &lt;span class="s1"&gt;"ISO-8859-1"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Characters, including whitespace, appear before the @charset rule */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Purpose of the @charset Rule
&lt;/h2&gt;

&lt;p&gt;The @charset rule is used to explicitly specify the character encoding within a stylesheet, rather than relying on the encoding of an external environment that, for whatever reason, does not match the stylesheet's encoding.&lt;/p&gt;

&lt;p&gt;It is recommended to use the standard encoding UTF-8 as the character encoding for stylesheets and HTML pages. Therefore, there is no need to use the @charset rule in stylesheets.&lt;/p&gt;
&lt;h3&gt;
  
  
  # Using the @charset Rule
&lt;/h3&gt;

&lt;p&gt;Although it is ideal to always use UTF-8 as the character encoding for stylesheets and HTML documents, this is not always the case in practice. For example, existing systems may use different encodings, or specific requirements may mandate the use of another encoding.&lt;/p&gt;

&lt;p&gt;It is used when a stylesheet contains non-ASCII characters and UTF-8 cannot always be used as the character encoding for the stylesheet and HTML documents.&lt;/p&gt;
&lt;h3&gt;
  
  
  - When UTF-8 Cannot Always Be Used as the Character Encoding for Stylesheets and HTML Pages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Even if a web server uses a different character encoding, such as ISO-8859-1, it is best practice to use the @charset rule to explicitly specify that a CSS file uses UTF-8 as its character encoding.&lt;/li&gt;
&lt;li&gt;Even if a stylesheet file uses a character encoding other than UTF-8, it is best practice to use the @charset rule to explicitly specify the actual character encoding of the CSS file.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  References
&lt;/h2&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://coding.courses/css-at-rule-charset/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fthemes%2Fcodingeverybody-en%2Fassets%2Fimages%2Fbranding%2Fsocial-share_img.png" height="420" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://coding.courses/css-at-rule-charset/" rel="noopener noreferrer" class="c-link"&gt;
            CSS @charset – Declaring Character Encoding for Stylesheets - codingCourses
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            The CSS @charset syntax rule is used to declare the character encoding of the stylesheet. It allows you to specify the desired character encoding for the stylesheet.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fuploads%2Ffavicon-wp-300x300.png" width="300" height="300"&gt;
          coding.courses
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>css</category>
      <category>charset</category>
    </item>
    <item>
      <title>CSS rem and em Units – Relative Length Units for Font Size</title>
      <dc:creator>Youn</dc:creator>
      <pubDate>Fri, 02 Oct 2026 05:40:35 +0000</pubDate>
      <link>https://dev.to/code1/css-rem-and-em-units-relative-length-units-for-font-size-1jmo</link>
      <guid>https://dev.to/code1/css-rem-and-em-units-relative-length-units-for-font-size-1jmo</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;😄 This post is based on the content from &lt;a href="https://coding.courses/css-rem-and-em-units/" rel="noopener noreferrer"&gt;coding.courses&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  rem and em Units
&lt;/h2&gt;

&lt;p&gt;The rem and em units are both relative length units that specify size or length based on the font-size (the text size) of a particular element.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The rem unit is based on the font-size of the root element, the &amp;lt;html&amp;gt; element.&lt;/li&gt;
&lt;li&gt;The em unit is based on the font-size of the element itself.&lt;/li&gt;
&lt;li&gt;For the font-size property being set, the parent element's font-size is used as the reference.&lt;/li&gt;
&lt;li&gt;For properties other than font-size, the current element's font size is used as the reference.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The rem Unit
&lt;/h2&gt;

&lt;p&gt;rem stands for "root element," and this unit is a relative length unit based on the font-size of the root &amp;lt;html&amp;gt; element, with 1rem equal to the root element's font size.&lt;br&gt;
For example, 1rem is equal to 1 times the &amp;lt;html&amp;gt; element's font size, and 1.5rem is equal to 1.5 times the font size.&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;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c"&gt;/* 2rem = 2 * 20px = 40px
       1rem = font size of the html element (20px) */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  # When the &amp;lt;html&amp;gt; Element's font-size Is Not Specified
&lt;/h3&gt;

&lt;p&gt;What happens to 1rem if the root &amp;lt;html&amp;gt; element's font-size is not specified?&lt;/p&gt;

&lt;p&gt;In this case, the font-size of the root &amp;lt;html&amp;gt; element is determined by the browser's default font size set by the user. Most users do not change the default browser font size. The default font size set by the browser is typically 16px, so in this case, 1rem equals 16px.&lt;/p&gt;
&lt;h3&gt;
  
  
  # When to Use the rem Unit
&lt;/h3&gt;
&lt;h4&gt;
  
  
  - Setting Global Styles
&lt;/h4&gt;

&lt;p&gt;Use rem for the overall styling of a web page, especially for setting base font sizes, spacing, and other layout-related properties.&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;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* 1rem = 16px */&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;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;    &lt;span class="c"&gt;/* 1rem = 16px */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* 2rem = 2 * 16px = 32px */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  - Using rem with Media Queries
&lt;/h4&gt;

&lt;p&gt;In responsive web design, you can use rem together with media queries to adjust styles according to screen size.&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;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;....&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;768px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.25rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* 20px */&lt;/span&gt;
        &lt;span class="c"&gt;/* 1.25rem = 1.25 * 16px = 20px
           1rem = font size of the current html element (16px) */&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;
  
  
  The em Unit
&lt;/h2&gt;

&lt;p&gt;em stands for "element," and this unit is based on the font size of the referenced element.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When applied to the font-size property, the parent element's font-size is used as the reference for 1em.&lt;/li&gt;
&lt;li&gt;For properties other than font-size, the current element's font size is used as the reference for 1em.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  # Applying em to the font-size Property
&lt;/h3&gt;

&lt;p&gt;When you use em as the value of the font-size property, 1em equals the parent element's font size.&lt;/p&gt;

&lt;p&gt;For example, font-size: 1em is equal to 1 times the parent element's font size, and font-size: 1.5em is equal to 1.5 times the parent element's font size.&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;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.7em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* 21px */&lt;/span&gt;
    &lt;span class="c"&gt;/* 0.7em = 0.7 * 30px = 21px;
       1em = font size of the parent element (h1, 30px) */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  # Applying em to Properties Other Than font-size
&lt;/h3&gt;

&lt;p&gt;When you use em for properties other than font-size, 1em equals the current element's font size.&lt;/p&gt;

&lt;p&gt;For example, line-height: 1em is equal to 1 times the current element's font size, and line-height: 1.5em is equal to 1.5 times the current element's font size.&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;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* 45px */&lt;/span&gt;
    &lt;span class="c"&gt;/* 1.5em = 1.5 * 30px = 45px
       1em = font size of this element (30px) */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  # When to Use the em Unit
&lt;/h3&gt;
&lt;h4&gt;
  
  
  - Typography-related Styles
&lt;/h4&gt;

&lt;p&gt;em is useful for setting sizes or lengths based on the current element's font size. This allows you to scale values proportionally, even if you do not know the exact font size of the element.&lt;/p&gt;

&lt;p&gt;For example, properties such as line-height and letter-spacing often use em to scale according to the current element's font size.&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;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* 45px */&lt;/span&gt;
    &lt;span class="c"&gt;/* 1.5em = 1.5 * 30px = 45px
       1em = font size of this element (30px) */&lt;/span&gt;
    &lt;span class="nl"&gt;letter-spacing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;-0.1em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* -3px */&lt;/span&gt;
    &lt;span class="c"&gt;/* -0.1em = -0.1 * 30px = -3px
       1em = font size of this element (30px) */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  - Layout and Spacing Relative to Current Font Size
&lt;/h4&gt;

&lt;p&gt;Using em for layout and spacing allows you to scale dimensions proportionally to the current font size. This is especially useful when the font size changes due to responsive design, as margins, padding, and other layout values will adjust automatically according to the font size.&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;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1em&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;
  
  
  References
&lt;/h2&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://coding.courses/css-rem-and-em-units/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fthemes%2Fcodingeverybody-en%2Fassets%2Fimages%2Fbranding%2Fsocial-share_img.png" height="420" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://coding.courses/css-rem-and-em-units/" rel="noopener noreferrer" class="c-link"&gt;
            CSS rem and em Units – Relative Length Units for Font Size - codingCourses
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            The rem and em units are both relative length units that specify size or length based on the font-size (the text size) of a particular element.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fuploads%2Ffavicon-wp-300x300.png" width="300" height="300"&gt;
          coding.courses
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>rem</category>
      <category>em</category>
      <category>css</category>
      <category>ai</category>
    </item>
    <item>
      <title>HTML id Attribute – Proper Understanding and Usage</title>
      <dc:creator>Youn</dc:creator>
      <pubDate>Wed, 30 Sep 2026 05:52:36 +0000</pubDate>
      <link>https://dev.to/code1/html-id-attribute-proper-understanding-and-usage-3bj7</link>
      <guid>https://dev.to/code1/html-id-attribute-proper-understanding-and-usage-3bj7</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;😄 This post is based on the content from &lt;a href="https://coding.courses/html-id-attribute/" rel="noopener noreferrer"&gt;coding.courses&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Definition and Usage
&lt;/h2&gt;

&lt;p&gt;The id attribute specifies a unique identifier (ID) for an element.&lt;br&gt;
The value of this attribute must be unique and distinct within the document (web page).&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic Example
&lt;/h2&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;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#section2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Go to Section 2&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- Click the link above to scroll down to this element --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"section2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Section 2 Content&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Practical Uses
&lt;/h2&gt;

&lt;p&gt;The id attribute is a global attribute.&lt;br&gt;
The unique identifier assigned to an element through this attribute can be used for various purposes.&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Using a Unique CSS Selector to Style an Element
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---- CSS ----
#css-selector { /* Select by id attribute value: #id-value selector */
    background-color: yellowgreen;
}

---- HTML ----
&amp;lt;p&amp;gt;Paragraph element.&amp;lt;/p&amp;gt;
&amp;lt;p id="css-selector"&amp;gt;Paragraph element.&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;Paragraph element.&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;Paragraph element.&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;CSS can apply styles by selecting HTML elements in various ways.&lt;/p&gt;

&lt;p&gt;Among these methods, you can also select an element using the value specified in the id attribute. As shown in the example above, enter the ID value after the hash symbol (#) (#css-selector).&lt;/p&gt;

&lt;p&gt;This allows you to apply styles specifically to the element whose ID value is css-selector. In the actual result, the background color of the element is styled with yellowgreen.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Identifying an Element with JavaScript
&lt;/h3&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;p&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"txt"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Welcome.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"btn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click to change the text&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;txt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;txt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Identify id="txt"&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;btn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;btn&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Identify id="btn"&lt;/span&gt;

    &lt;span class="nx"&gt;btn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;txt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Nice to meet you.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In the code example above, clicking the  element with id="btn" changes the text of the element with id="txt" from "Welcome." to "Nice to meet you.".&lt;/p&gt;


&lt;p&gt;At this point, when JavaScript identifies the &lt;/p&gt; element with id="btn" or the element with id="txt", both elements are identified using the values specified in their id attributes.
&lt;h3&gt;
  
  
  3. Identifying an Element with a URL Fragment
&lt;/h3&gt;

&lt;p&gt;First, let's look at what a fragment in a URL (or URI) is. A URL consists of parts such as a domain and the path commonly used to access a web page. Here is an example of a URL that includes a hash symbol (#) at the end of a typical URL.&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://www.example.com#example
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;Here, it refers to the #example portion highlighted in red. This is called a fragment or a hash URL.&lt;/p&gt;

&lt;p&gt;In a URL, the fragment is the string that follows the hash symbol (#), and it corresponds to the value specified in the id attribute within the web page of that URL. When a web page with a fragment in its URL is loaded, the browser finds the element whose id attribute value matches the fragment and scrolls the page so that the element appears at the top of the visible area of the screen (called the viewport).&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#section2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Go to Section 2&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- Click the link above to scroll down to this element --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"section2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;Section 2 Content&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;



&lt;h2&gt;
  
  
  Naming Rules for the id Attribute Value
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The value of this attribute must be unique and distinct within the document (web page).&lt;/li&gt;
&lt;li&gt;The id attribute value must contain one or more characters with no whitespace characters (such as spaces or tabs).&lt;/li&gt;
&lt;li&gt;It can consist entirely of numbers, start with a number, start with an underscore (_), or consist solely of punctuation marks (.). There are no other specific restrictions.&lt;/li&gt;
&lt;li&gt;It is case-sensitive.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Things to Keep in Mind
&lt;/h2&gt;

&lt;p&gt;It must be unique and distinct within the document (web page).&lt;br&gt;
If there are duplicate id attribute values, unexpected errors may occur across all CSS, JavaScript, and other applications built on the assumption that the id attribute value is a unique identifier, such as when using it as a unique CSS selector to style the element, identifying it via JavaScript, or targeting it as a URL fragment identifier.&lt;/p&gt;
&lt;h2&gt;
  
  
  References
&lt;/h2&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://coding.courses/html-id-attribute/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fthemes%2Fcodingeverybody-en%2Fassets%2Fimages%2Fbranding%2Fsocial-share_img.png" height="420" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://coding.courses/html-id-attribute/" rel="noopener noreferrer" class="c-link"&gt;
            HTML id Attribute – Proper Understanding and Usage - codingCourses
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            The id attribute specifies a unique identifier (ID) for an element. The value of this attribute must be unique and distinct within the document (web page).
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fuploads%2Ffavicon-wp-300x300.png" width="300" height="300"&gt;
          coding.courses
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;




</description>
      <category>html</category>
      <category>id</category>
      <category>attribute</category>
    </item>
    <item>
      <title>HTML class Attribute</title>
      <dc:creator>Youn</dc:creator>
      <pubDate>Mon, 28 Sep 2026 05:06:07 +0000</pubDate>
      <link>https://dev.to/code1/html-class-attribute-5gdd</link>
      <guid>https://dev.to/code1/html-class-attribute-5gdd</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;😄 This post is based on the content from &lt;a href="https://coding.courses/html-class-attribute/" rel="noopener noreferrer"&gt;coding.courses&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Definition and Usage
&lt;/h2&gt;

&lt;p&gt;The class attribute specifies one or more class names for an element.&lt;br&gt;
Multiple elements can share the same class names, which are used by CSS and JavaScript to classify, identify, select, style, and manipulate elements.&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic Example
&lt;/h2&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;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"alert"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;This is an announcement.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"alert caution"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Proceed with caution.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Practical Uses
&lt;/h2&gt;

&lt;p&gt;To specify multiple class names for a single element, separate the class names with spaces in the value of the class attribute.&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;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"alert caution"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Proceed with caution.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In addition, multiple elements can share the same class names.&lt;/p&gt;

&lt;p&gt;The class attribute is used for the following purposes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In CSS, class names are used as selectors to classify, identify, select, style, and manipulate elements.&lt;/li&gt;
&lt;li&gt;Like CSS, in JavaScript, class names are also used to classify, identify, select, style, and manipulate elements.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  #Using Class in CSS
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;---- HTML ----
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"alert"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;This is an announcement.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Paragraph element.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"alert caution"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Proceed with caution.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Paragraph element.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;

---- CSS ----
.alert { /* Selects the alert class: .class selector */
    padding: 0.5em;
    background-color: gold;
}
.caution { /* Selects the caution class: .class selector */
    color: orangered;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The CSS .alert selector targets and styles elements whose class name is alert. In addition, the CSS .caution selector targets and styles elements whose class name is caution.&lt;/p&gt;

&lt;p&gt;The  &amp;lt;p class="alert caution"&amp;gt;Proceed with caution. &amp;lt;/p&amp;gt; element has two class names: alert and caution.&lt;br&gt;
Because this element matches both the .alert and .caution selectors, the styles defined by both selectors are applied.&lt;/p&gt;
&lt;h3&gt;
  
  
  # Using Class in JavaScript
&lt;/h3&gt;

&lt;p&gt;The following example contains ten &amp;lt;div&amp;gt; elements. Seven of those &amp;lt;div&amp;gt; elements have the class name box.&lt;/p&gt;

&lt;p&gt;When the button is clicked, JavaScript identifies only the elements with the class name box and changes their text from "box class" to "Hello from the box class."&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;HTML
&lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c"&gt;/* Styles all div elements */&lt;/span&gt;
        &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.5em&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;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;margin-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.5em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nc"&gt;.box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c"&gt;/* Adds a background color only to div elements with the box class */&lt;/span&gt;
        &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;gold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;box class&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;box class&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;box class&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;box class&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;div&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;div&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;box class&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;box class&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;div&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;box class&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"highlight-button"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click to Change Text&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;highlightButton&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;highlight-button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;highlightButton&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// document.querySelectorAll(".box") : Selects all elements with the class name "box"&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;boxes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.box&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nx"&gt;boxes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;box&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello from the box class.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As shown in this example, JavaScript uses class names to identify, select, style, and manipulate elements.&lt;/p&gt;
&lt;h2&gt;
  
  
  References
&lt;/h2&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://coding.courses/html-class-attribute/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fthemes%2Fcodingeverybody-en%2Fassets%2Fimages%2Fbranding%2Fsocial-share_img.png" height="420" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://coding.courses/html-class-attribute/" rel="noopener noreferrer" class="c-link"&gt;
            HTML class Attribute – Proper Understanding and Usage - codingCourses
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            The class attribute specifies one or more class names for an element. Multiple elements can share the same class names, which are used by CSS and JavaScript to classify, identify, select, style, and manipulate elements.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fuploads%2Ffavicon-wp-300x300.png" width="300" height="300"&gt;
          coding.courses
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>html</category>
      <category>class</category>
      <category>attribute</category>
    </item>
    <item>
      <title>HTML lang Attribute</title>
      <dc:creator>Youn</dc:creator>
      <pubDate>Wed, 23 Sep 2026 02:43:45 +0000</pubDate>
      <link>https://dev.to/code1/html-lang-attribute-2a2k</link>
      <guid>https://dev.to/code1/html-lang-attribute-2a2k</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;😄 This post is based on the content from &lt;a href="https://coding.courses/html-lang-attribute/" rel="noopener noreferrer"&gt;coding.courses&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Definition and Usage
&lt;/h2&gt;

&lt;p&gt;The lang attribute specifies the primary language of an element's content and of any text-containing attributes.&lt;br&gt;
Using this attribute provides language information for human-readable content that can be used by screen readers, browsers, and search engines.&lt;/p&gt;
&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;This is a global attribute that can be applied to any HTML element.&lt;/li&gt;
&lt;li&gt;The lang attribute value is inherited by child elements.&lt;/li&gt;
&lt;li&gt;The default value of the lang attribute is unknown, so it is recommended to always set this attribute to an appropriate value.&lt;/li&gt;
&lt;li&gt;If the attribute value is an empty string (lang=""), the language is set to unknown.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Using the lang attribute provides the following benefits:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Allows screen readers to recognize the language of a web page and provide speech output in the appropriate language.&lt;/li&gt;
&lt;li&gt;Enables browsers, such as Chrome, to automatically detect the page language for translation features.&lt;/li&gt;
&lt;li&gt;Helps search engines identify the language of the web page and deliver search results in the corresponding language.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;
&lt;h3&gt;
  
  
  # Specifying the Primary Language for a Page
&lt;/h3&gt;

&lt;p&gt;To set the primary language of the page text, always use the lang attribute on the root &amp;lt;html&amp;gt; tag.&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;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  # When a Page Contains Content in Another Language
&lt;/h3&gt;

&lt;p&gt;If a page contains content in a different language, add the lang attribute to the tag wrapping that content.&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;p&amp;gt;&lt;/span&gt;The title is "&lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"fr"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Le Bon Usage&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;".&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Things to Keep in Mind
&lt;/h2&gt;
&lt;h3&gt;
  
  
  # Applies to Text-Containing Attributes as Well
&lt;/h3&gt;

&lt;p&gt;The lang attribute specifies the primary language not only for a tag's content but also for all text-containing attributes.&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;a&lt;/span&gt; &lt;span class="na"&gt;title=&lt;/span&gt;&lt;span class="s"&gt;"Spanish"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"qa-html-language-declarations.es"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"es"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Español&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  # When There Is No Appropriate Markup Around the Content
&lt;/h3&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;p&amp;gt;&lt;/span&gt;This content is in Chinese: &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"zh-Hans"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;中国科学院文献情报中心&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://coding.courses/html-lang-attribute/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fthemes%2Fcodingeverybody-en%2Fassets%2Fimages%2Fbranding%2Fsocial-share_img.png" height="420" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://coding.courses/html-lang-attribute/" rel="noopener noreferrer" class="c-link"&gt;
            HTML lang Attribute – Proper Understanding and Usage - codingCourses
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            The lang attribute specifies the primary language of an element's content and of any text-containing attributes.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fuploads%2Ffavicon-wp-300x300.png" width="300" height="300"&gt;
          coding.courses
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>lang</category>
      <category>attribute</category>
      <category>html</category>
    </item>
    <item>
      <title>JavaScript String slice() Function – Slice a String by Index Range</title>
      <dc:creator>Youn</dc:creator>
      <pubDate>Tue, 22 Sep 2026 03:21:40 +0000</pubDate>
      <link>https://dev.to/code1/javascript-string-slice-function-slice-a-string-by-index-range-5c91</link>
      <guid>https://dev.to/code1/javascript-string-slice-function-slice-a-string-by-index-range-5c91</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;😄 This post is based on the content from &lt;a href="https://coding.courses/javascript-string-slice-function/" rel="noopener noreferrer"&gt;coding.courses&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Definition and Usage
&lt;/h2&gt;

&lt;p&gt;The slice() function for strings slices a string by a specified index range and returns a new string.&lt;br&gt;
Using this function, you can easily slice and extract a string within the desired range.&lt;/p&gt;
&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The string sliced by the specified index range is returned as a new string.&lt;/li&gt;
&lt;li&gt;The index range is determined by the start and end parameters you specify (the end index is not included).&lt;/li&gt;
&lt;li&gt;With this behavior, the original string remains unchanged.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Basic Example
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/**
 * A function that slices a specific range of a string
 * and returns the result as a new string.
 *
 * str.slice(beginIndex[, endIndex])
 *
 * @param {number} beginIndex - The starting index of the substring to extract.
 * @param {number} endIndex - The ending index of the substring to extract (not included).
 * @returns {string} - The extracted substring.
 */&lt;/span&gt;

&lt;span class="cm"&gt;/*
 * Note:
 * In strings, indexes start at 0.
 * The first character has an index of 0, and the second character has an index of 1.
 */&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Welcome. This is codingCourses.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;welcome&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;welcome&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: "Welcome"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;courseName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;courseName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: "codingCourses"&lt;/span&gt;

&lt;span class="cm"&gt;/* 👇 The original string remains unchanged. */&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: "Welcome. This is codingCourses."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Syntax
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;str.slice(beginIndex[, endIndex])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;str is the string to which the slice() function is applied.&lt;/p&gt;
&lt;h2&gt;
  
  
  Parameters
&lt;/h2&gt;
&lt;h3&gt;
  
  
  # beginIndex
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;If omitted, the default value is 0.&lt;/li&gt;
&lt;li&gt;If omitted, the default value is 0.&lt;/li&gt;
&lt;li&gt;Negative values can be used, counting backward from the end of the string.&lt;/li&gt;
&lt;li&gt;If greater than or equal to the length of the string (str.length), no characters are extracted.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  # endIndex
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Optional. Specifies the index at which to end extraction.&lt;/li&gt;
&lt;li&gt;slice() extracts characters up to, but not including this endIndex index.&lt;/li&gt;
&lt;li&gt;If omitted, extraction continues to the end of the string.&lt;/li&gt;
&lt;li&gt;Negative values can be used, counting backward from the end of the string.&lt;/li&gt;
&lt;li&gt;If greater than or equal to the length of the string (str.length), extraction continues to the end of the string.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Return Value
&lt;/h2&gt;

&lt;p&gt;The slice() function for strings extracts characters from the original string within the specified index range and returns them as a new string. The returned string is a copy of the selected characters, so the original string remains unchanged.&lt;/p&gt;
&lt;h3&gt;
  
  
  # Parameter and Return Value Examples
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;str1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Welcome!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// The length of str1 is 8&lt;/span&gt;
    &lt;span class="nx"&gt;str2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nx"&gt;str3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="nx"&gt;str4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="nx"&gt;str5&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;str1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: "elcome!"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: "ome"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: "Welcome!"&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;str5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Output: ""&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://coding.courses/javascript-string-slice-function/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fthemes%2Fcodingeverybody-en%2Fassets%2Fimages%2Fbranding%2Fsocial-share_img.png" height="420" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://coding.courses/javascript-string-slice-function/" rel="noopener noreferrer" class="c-link"&gt;
            JavaScript String slice() Function – Slice a String by Index Range - codingCourses
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            The slice() function for strings slices a string by an index range and returns a new string without modifying the original string.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fuploads%2Ffavicon-wp-300x300.png" width="300" height="300"&gt;
          coding.courses
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>javascript</category>
      <category>slice</category>
      <category>string</category>
    </item>
    <item>
      <title>HTML cite Attribute – Referencing the Source URL</title>
      <dc:creator>Youn</dc:creator>
      <pubDate>Thu, 17 Sep 2026 05:36:34 +0000</pubDate>
      <link>https://dev.to/code1/html-cite-attribute-referencing-the-source-url-2efk</link>
      <guid>https://dev.to/code1/html-cite-attribute-referencing-the-source-url-2efk</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;😄 This post is based on the content from &lt;a href="https://coding.courses/html-cite-attribute/" rel="noopener noreferrer"&gt;coding.courses&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Definition and Usage
&lt;/h2&gt;

&lt;p&gt;The cite attribute specifies a URL that references the source of a quote or change.&lt;/p&gt;

&lt;p&gt;This attribute is used with tags such as &amp;lt;q&amp;gt;, &amp;lt;blockquote&amp;gt;, &lt;a href="https://coding.courses/html-ins-tag/" rel="noopener noreferrer"&gt;&amp;lt;ins&amp;gt;&lt;/a&gt;, and &amp;lt;del&amp;gt;.&lt;br&gt;
It enhances information credibility by providing source details for quotes or changes, enabling authors and search engines to utilize this information.&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic Example
&lt;/h2&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;p&amp;gt;&lt;/span&gt;
    Tim Berners-Lee said:
    &lt;span class="nt"&gt;&amp;lt;q&lt;/span&gt; &lt;span class="na"&gt;cite=&lt;/span&gt;&lt;span class="s"&gt;"https://example.com/example"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        The internet is a human right.
    &lt;span class="nt"&gt;&amp;lt;/q&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;
&lt;h3&gt;
  
  
  # Using the cite Attribute with &amp;lt;q&amp;gt;
&lt;/h3&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;p&amp;gt;&lt;/span&gt;
    Here is a famous quote:
    &lt;span class="nt"&gt;&amp;lt;q&lt;/span&gt; &lt;span class="na"&gt;cite=&lt;/span&gt;&lt;span class="s"&gt;"https://www.brainyquote.com/quotes/albert_einstein_100134"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        Imagination is limitless. Knowledge is limited.
    &lt;span class="nt"&gt;&amp;lt;/q&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  # Using the cite Attribute with &amp;lt;blockquote&amp;gt;
&lt;/h3&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;p&amp;gt;&lt;/span&gt;The following is a quotation from Wikipedia.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;blockquote&lt;/span&gt; &lt;span class="na"&gt;cite=&lt;/span&gt;&lt;span class="s"&gt;"https://en.wikipedia.org/wiki/Romeo_and_Juliet"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
        The Tragedy of Romeo and Juliet, often shortened to Romeo and Juliet,
        is a tragedy written by William Shakespeare about the romance
        between two young Italians from feuding families.
        It was among Shakespeare's most popular plays during his lifetime and,
        along with Hamlet, is one of his most frequently performed. Today,
        the title characters are regarded as archetypal young lovers.
    &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/blockquote&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  # Using the cite Attribute with &amp;lt;ins&amp;gt;
&lt;/h3&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;p&amp;gt;&lt;/span&gt;
    Here is a description of the latest update:
    &lt;span class="nt"&gt;&amp;lt;ins&lt;/span&gt; &lt;span class="na"&gt;cite=&lt;/span&gt;&lt;span class="s"&gt;"https://example.com/changelog"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        Latest update details...
    &lt;span class="nt"&gt;&amp;lt;/ins&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  # Using the cite Attribute with &amp;lt;del&amp;gt;
&lt;/h3&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;p&amp;gt;&lt;/span&gt;
    The following feature has been removed:
    &lt;span class="nt"&gt;&amp;lt;del&lt;/span&gt; &lt;span class="na"&gt;cite=&lt;/span&gt;&lt;span class="s"&gt;"https://example.com/changelog"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        Details about the removed feature...
    &lt;span class="nt"&gt;&amp;lt;/del&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://coding.courses/html-cite-attribute/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fthemes%2Fcodingeverybody-en%2Fassets%2Fimages%2Fbranding%2Fsocial-share_img.png" height="420" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://coding.courses/html-cite-attribute/" rel="noopener noreferrer" class="c-link"&gt;
            HTML cite Attribute – Referencing the Source URL - codingCourses
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            The cite attribute specifies the source URL of a quote or change, and is used in q, blockquote, ins, and del tags. It helps authors and search engines understand the source of the quoted or modified content.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fuploads%2Ffavicon-wp-300x300.png" width="300" height="300"&gt;
          coding.courses
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>html</category>
      <category>cite</category>
    </item>
    <item>
      <title>HTML data-* Attributes</title>
      <dc:creator>Youn</dc:creator>
      <pubDate>Tue, 15 Sep 2026 05:49:13 +0000</pubDate>
      <link>https://dev.to/code1/html-data-attributes-2icc</link>
      <guid>https://dev.to/code1/html-data-attributes-2icc</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;😄 This post is based on the content from &lt;a href="https://coding.courses/html-data-attributes/" rel="noopener noreferrer"&gt;coding.courses&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Definition and Usage
&lt;/h2&gt;

&lt;p&gt;The data-* attributes are standard HTML 'custom data attributes' beyond those predefined by HTML.&lt;br&gt;
They are created by combining the data- prefix with a custom name, allowing you to store custom data in the attribute's value.&lt;/p&gt;

&lt;p&gt;Custom data attributes are used to store custom 'data,' 'state,' 'annotations,' and similar information for a page or application.&lt;br&gt;
They are standardized HTML attributes used when no other appropriate standard attribute or element exists.&lt;br&gt;
As global attributes, they can be applied to any HTML element.&lt;/p&gt;

&lt;p&gt;They are primarily used in JavaScript and CSS to add dynamic functionality or apply styling.&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic Example
&lt;/h2&gt;

&lt;p&gt;This example demonstrates how to use custom data attributes with JavaScript to display basic product information. Clicking the 'View Product Details' button displays an alert showing the product's details.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;---- HTML ----
&lt;span class="c"&gt;&amp;lt;!-- The data-* attributes are used to store product information.
     Each attribute represents:
     product name (data-name),
     price (data-price),
     stock (data-stock),
     and color (data-color).
--&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; 
    &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"product-12345"&lt;/span&gt;
    &lt;span class="na"&gt;data-name=&lt;/span&gt;&lt;span class="s"&gt;"Sneakers"&lt;/span&gt;
    &lt;span class="na"&gt;data-price=&lt;/span&gt;&lt;span class="s"&gt;"10000"&lt;/span&gt;
    &lt;span class="na"&gt;data-stock=&lt;/span&gt;&lt;span class="s"&gt;"5"&lt;/span&gt;
    &lt;span class="na"&gt;data-color=&lt;/span&gt;&lt;span class="s"&gt;"red"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Sneakers
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- The button includes a data-product-id attribute
     that identifies the corresponding product ID.
--&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt;
    &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt;
    &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"product-details"&lt;/span&gt;
    &lt;span class="na"&gt;data-product-id=&lt;/span&gt;&lt;span class="s"&gt;"product-12345"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    View Product Details
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

---- JavaScript ----
const viewDetails = document.getElementById("product-details");

viewDetails.addEventListener("click", function() {
    const productId = this.dataset.productId;
    const product = document.getElementById(productId);

    /* Retrieves product name, price, stock, and color
       using data attributes from the product element. */
    const productName = product.dataset.name;
    const price = product.dataset.price;
    const stock = product.dataset.stock;
    const color = product.dataset.color;

    /* Combines the retrieved product information into a string
       and displays it in an alert dialog. */
    const msg = "Product Name: " + productName +
                "\nPrice: " + price + " USD" +
                "\nStock: " + stock + " pcs" + 
                "\nColor: " + color;          
    alert(msg);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Purpose of Use
&lt;/h2&gt;

&lt;p&gt;The data-* attributes are designed to allow custom data to be added to HTML elements in a standardized way, without the need for non-standard elements, semantically inappropriate attributes, or unnecessary workarounds.&lt;br&gt;
By using these attributes, developers can easily attach their own data to HTML elements in a consistent manner.&lt;/p&gt;
&lt;h2&gt;
  
  
  Using Data Attributes in CSS
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;---- HTML ----
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; 
    &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"product-12345"&lt;/span&gt;
    &lt;span class="na"&gt;data-name=&lt;/span&gt;&lt;span class="s"&gt;"Sneakers"&lt;/span&gt;
    &lt;span class="na"&gt;data-price=&lt;/span&gt;&lt;span class="s"&gt;"10000"&lt;/span&gt;
    &lt;span class="na"&gt;data-stock=&lt;/span&gt;&lt;span class="s"&gt;"5"&lt;/span&gt;
    &lt;span class="na"&gt;data-color=&lt;/span&gt;&lt;span class="s"&gt;"red"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Sneakers
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

---- CSS ----
[data-name] { /* Targeted using a CSS attribute selector */
    padding: 1em;
    background-color: yellowgreen;
}
[data-color="red"] { /* Targeted using a CSS attribute selector */
    color: red;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://coding.courses/html-data-attributes/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fthemes%2Fcodingeverybody-en%2Fassets%2Fimages%2Fbranding%2Fsocial-share_img.png" height="420" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://coding.courses/html-data-attributes/" rel="noopener noreferrer" class="c-link"&gt;
            HTML data-* Attributes – Standard Custom Data Attributes - codingCourses
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            The data-* attributes are standard HTML 'custom data attributes' beyond those predefined by HTML. They are created by combining the data- prefix with a custom name, allowing you to store custom data in the attribute's value.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fuploads%2Ffavicon-wp-300x300.png" width="300" height="300"&gt;
          coding.courses
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>attributes</category>
      <category>html</category>
      <category>data</category>
    </item>
    <item>
      <title>HTML &lt;details&gt; Tag</title>
      <dc:creator>Youn</dc:creator>
      <pubDate>Thu, 10 Sep 2026 01:59:42 +0000</pubDate>
      <link>https://dev.to/code1/html-tag-3182</link>
      <guid>https://dev.to/code1/html-tag-3182</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;😄 This post is based on the content from &lt;a href="https://coding.courses/html-details-tag/" rel="noopener noreferrer"&gt;coding.courses&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Definition and Usage
&lt;/h2&gt;

&lt;p&gt;The &amp;lt;details&amp;gt; tag defines content that users can choose to open or close.&lt;br&gt;
It is typically used to provide additional information or details. According to the specification, it represents a disclosure widget that allows users to access extra information or controls.&lt;br&gt;
The &amp;lt;details&amp;gt; tag is commonly used to create interactive widgets, such as accordions, that users can expand or collapse.&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic Example
&lt;/h2&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;details&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;Summary content&lt;span class="nt"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
    Additional information or details.
&lt;span class="nt"&gt;&amp;lt;/details&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Usage Notes
&lt;/h2&gt;

&lt;p&gt;To use the &amp;lt;details&amp;gt; tag effectively, you need to understand the &amp;lt;summary&amp;gt; tag.&lt;br&gt;
By default, the &lt;a href="https://coding.courses/html-summary-tag/" rel="noopener noreferrer"&gt;&amp;lt;summary&amp;gt;&lt;/a&gt; tag displays a marker shaped like a ► arrow.&lt;/p&gt;
&lt;h2&gt;
  
  
  Syntax
&lt;/h2&gt;

&lt;p&gt;You can include any type of content inside the &amp;lt;details&amp;gt; tag, but using the &amp;lt;summary&amp;gt; tag indicates the title (summary content). If the &amp;lt;summary&amp;gt; tag is omitted, the user agent (such as a browser) provides its own default title (e.g., "Details").&lt;/p&gt;
&lt;h4&gt;
  
  
  Example with the &amp;lt;summary&amp;gt; Tag
&lt;/h4&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;details&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;Summary content&lt;span class="nt"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- The &amp;lt;summary&amp;gt; tag represents the title --&amp;gt;&lt;/span&gt;
    Additional information or details.
&lt;span class="nt"&gt;&amp;lt;/details&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Example without the &amp;lt;summary&amp;gt; Tag
&lt;/h4&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;details&amp;gt;&lt;/span&gt;
    Additional information or details.
&lt;span class="nt"&gt;&amp;lt;/details&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  The open Attribute
&lt;/h3&gt;

&lt;p&gt;The open attribute is a boolean attribute.&lt;br&gt;
When this attribute is present, both the summary and the additional content are visible to the user. If the attribute is omitted, only the summary is shown.&lt;br&gt;
By default, the widget is collapsed. When it is expanded, the content becomes visible. If desired, the open attribute can be used to keep the widget open by default.&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;details&lt;/span&gt; &lt;span class="na"&gt;open&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- The widget is open by default when the open attribute is present --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;Summary content&lt;span class="nt"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
    Additional information or details.
&lt;span class="nt"&gt;&amp;lt;/details&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

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


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://coding.courses/html-details-tag/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fthemes%2Fcodingeverybody-en%2Fassets%2Fimages%2Fbranding%2Fsocial-share_img.png" height="420" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://coding.courses/html-details-tag/" rel="noopener noreferrer" class="c-link"&gt;
            HTML &amp;lt;details&amp;gt; Tag – The Details Disclosure Element - codingCourses
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            The details tag defines content that users can choose to open or close. It is commonly used to provide additional or detailed information. This article also covers the open attribute used with the details tag.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fuploads%2Ffavicon-wp-300x300.png" width="300" height="300"&gt;
          coding.courses
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>html</category>
      <category>details</category>
    </item>
    <item>
      <title>HTML &lt;link rel="preload"&gt;</title>
      <dc:creator>Youn</dc:creator>
      <pubDate>Tue, 08 Sep 2026 05:07:09 +0000</pubDate>
      <link>https://dev.to/code1/html-5ddb</link>
      <guid>https://dev.to/code1/html-5ddb</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;😄 This post is based on the content from &lt;a href="https://coding.courses/html-link-relpreload/" rel="noopener noreferrer"&gt;coding.courses&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Definition and Usage
&lt;/h2&gt;

&lt;p&gt;The rel="preload" attribute of the &lt;a href="https://coding.courses/html-link-tag/" rel="noopener noreferrer"&gt;&amp;lt;link&amp;gt;&lt;/a&gt; tag specifies that the browser should preemptively fetch the resource specified by the href attribute and store it in the cache to preload it. It is used within the &lt;a href="https://coding.courses/html-head-tag/" rel="noopener noreferrer"&gt;&amp;lt;head&amp;gt;&lt;/a&gt; tag and is mainly used to preload resources needed by the current page, such as web fonts, images, and CSS files.&lt;br&gt;
This tag must be the first child element of the root &amp;lt;html&amp;gt; element, and the second child element of &amp;lt;html&amp;gt; is the &amp;lt;body&amp;gt; element.&lt;/p&gt;
&lt;h2&gt;
  
  
  Basic Example
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- Character encoding --&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;The title of this page&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- Document title --&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"description"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"A short description of this page."&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- Document description --&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"style.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- Stylesheet --&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- Script --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="c"&gt;&amp;lt;!-- The document's content --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;&amp;lt;!DOCTYPE html&amp;gt;: This part declares the document type and serves to ensure that the browser follows the latest web standards and renders the document correctly. It is not an HTML element.&lt;/li&gt;
&lt;li&gt;&amp;lt;html&amp;gt;: The root element, which is the top-level element of an HTML document. All HTML elements must be contained within the &amp;lt;html&amp;gt; element.&lt;/li&gt;
&lt;li&gt;&amp;lt;head&amp;gt;: This part defines the metadata and header information of the HTML document. It provides information about the document to the browser and can be used to link external stylesheets, JavaScript files, and more.&lt;/li&gt;
&lt;li&gt;&amp;lt;body&amp;gt;: This part defines the body content of the HTML document. The content that is actually displayed on the web page is written in this section, and various elements such as text, images, links, tables, and forms can be included.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Technical Summary
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &amp;lt;head&amp;gt; tag is a required tag that is essential for the basic structure of HTML.&lt;/li&gt;
&lt;li&gt;A standards-compliant HTML document must contain only one &amp;lt;head&amp;gt; tag.&lt;/li&gt;
&lt;li&gt;The &amp;lt;head&amp;gt; tag must be the first child element of the &amp;lt;html&amp;gt; element.&lt;/li&gt;
&lt;li&gt;The &amp;lt;head&amp;gt; tag must have the &amp;lt;body&amp;gt; element as a sibling element. In this structure, the &amp;lt;body&amp;gt; element must be positioned second.&lt;/li&gt;
&lt;li&gt;The &amp;lt;head&amp;gt; tag must contain a &amp;lt;title&amp;gt; element as a child element, unless the title information is provided by a parent document (such as an &amp;lt;iframe&amp;gt;) or by a higher-level protocol (such as the subject line of an HTML email). This element provides the title of the HTML document.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  References
&lt;/h2&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://coding.courses/html-link-relpreload/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fthemes%2Fcodingeverybody-en%2Fassets%2Fimages%2Fbranding%2Fsocial-share_img.png" height="420" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://coding.courses/html-link-relpreload/" rel="noopener noreferrer" class="c-link"&gt;
            HTML &amp;lt;link rel="preload"&amp;gt; – Proper Understanding and Usage - codingCourses
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            The rel="preload" attribute of the link tag specifies that the browser should preemptively fetch the resource specified by the href attribute and store it in the cache to preload it.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fuploads%2Ffavicon-wp-300x300.png" width="300" height="300"&gt;
          coding.courses
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>html</category>
      <category>link</category>
      <category>preload</category>
    </item>
    <item>
      <title>HTML &lt;link rel="preconnect"&gt;</title>
      <dc:creator>Youn</dc:creator>
      <pubDate>Thu, 03 Sep 2026 03:10:29 +0000</pubDate>
      <link>https://dev.to/code1/html-219m</link>
      <guid>https://dev.to/code1/html-219m</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;😄 This post is based on the content from &lt;a href="https://coding.courses/html-link-relpreconnect/" rel="noopener noreferrer"&gt;coding.courses&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Definition and Usage
&lt;/h2&gt;

&lt;p&gt;The rel="preconnect" attribute of the &lt;a href="https://coding.courses/html-link-tag/" rel="noopener noreferrer"&gt;&amp;lt;link&amp;gt;&lt;/a&gt; tag specifies that the browser should preemptively establish a connection to the external domain specified by the href attribute.&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;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"preconnect"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://another-domain.com"&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;This allows the browser to reduce the time required to establish a connection to an external domain, making it faster to load resources from that domain (such as images, scripts, and fonts).&lt;/p&gt;

&lt;p&gt;Before requesting resources from an external domain, the browser performs several connection steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It looks up the domain name to find the server's IP address. This is called a DNS (Domain Name System) lookup.&lt;/li&gt;
&lt;li&gt;After confirming the IP address, it establishes a connection to exchange data with the server. This is called a TCP (Transmission Control Protocol) connection.&lt;/li&gt;
&lt;li&gt;If a secure connection such as HTTPS is required, the browser establishes a secure connection via a TLS (Transport Layer Security) handshake.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These connection processes can vary depending on network conditions and may introduce a certain amount of latency when the browser first requests resources from an external domain.&lt;/p&gt;
&lt;h2&gt;
  
  
  Preconnecting to External Domains
&lt;/h2&gt;

&lt;p&gt;The &amp;lt;link&amp;gt; tag's rel="preconnect" attribute allows the browser to establish a connection in advance to the external domain specified by the href attribute. This allows the browser to reduce the time required to establish a connection to an external domain, making it faster to load resources from that domain.&lt;/p&gt;

&lt;p&gt;The simplest way to preconnect to an external domain is to add the &amp;lt;link&amp;gt; tag to the document's &lt;a href="https://coding.courses/html-head-tag/" rel="noopener noreferrer"&gt;&amp;lt;head&amp;gt;&lt;/a&gt; tag.&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;head&amp;gt;&lt;/span&gt;
    ...
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"preconnect"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.googleapis.com"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.googleapis.com/css2?family=Roboto+Mono:ital@0;1&amp;amp;display=swap"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    ...
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The example above connects a stylesheet provided by Google to use Google Web Fonts.&lt;/p&gt;

&lt;p&gt;The URL (&lt;a href="https://fonts.googleapis.com" rel="noopener noreferrer"&gt;https://fonts.googleapis.com&lt;/a&gt;) of the stylesheet provided by Google is an external domain. In the example above, the rel="preconnect" attribute of the &amp;lt;link&amp;gt; tag is used to specify that the browser should establish a connection in advance to the &lt;a href="https://fonts.googleapis.com" rel="noopener noreferrer"&gt;https://fonts.googleapis.com&lt;/a&gt; domain.&lt;/p&gt;

&lt;p&gt;By specifying the external domain to preconnect to with the rel="preconnect" attribute of the &amp;lt;link&amp;gt; tag before requesting external resources, the browser prepares a connection to that domain in advance, reducing the time required to load resources afterward. You can repeat the above code for each external domain you want to preconnect to.&lt;/p&gt;
&lt;h2&gt;
  
  
  Important Considerations
&lt;/h2&gt;
&lt;h3&gt;
  
  
  # Apply Only to Necessary External Domains
&lt;/h3&gt;

&lt;p&gt;The rel="preconnect" attribute of the &amp;lt;link&amp;gt; tag is quite useful, but applying it to every external domain can be counterproductive. This is because it can create unnecessary overhead for the browser and reduce the actual benefits of preconnecting. Be careful not to preconnect to too many external domains.&lt;/p&gt;

&lt;p&gt;If you need to preconnect to many external domains, using the rel="dns-prefetch" attribute of the &amp;lt;link&amp;gt; tag is recommended.&lt;/p&gt;

&lt;p&gt;The rel="dns-prefetch" attribute of the &amp;lt;link&amp;gt; tag can reduce DNS lookup time by allowing the browser to perform the DNS lookup, which is the first step in connecting to an external domain, in advance. Therefore, compared to the rel="preconnect" attribute of the &amp;lt;link&amp;gt; tag, it requires fewer connection-related tasks from the browser and can reduce the negative impact (such as performance degradation) on initial loading performance when used for multiple external domains.&lt;/p&gt;
&lt;h3&gt;
  
  
  # No Effect on the Same Domain
&lt;/h3&gt;

&lt;p&gt;The rel="preconnect" attribute of the &amp;lt;link&amp;gt; tag saves the time required to establish a connection to an external domain. Because the same domain is already connected, preconnecting to it has no effect.&lt;/p&gt;
&lt;h2&gt;
  
  
  References
&lt;/h2&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://coding.courses/html-link-relpreconnect/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fthemes%2Fcodingeverybody-en%2Fassets%2Fimages%2Fbranding%2Fsocial-share_img.png" height="auto" class="m-0"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://coding.courses/html-link-relpreconnect/" rel="noopener noreferrer" class="c-link"&gt;
            HTML &amp;lt;link rel="preconnect"&amp;gt; – Proper Understanding and Usage - codingCourses
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            The rel="preconnect" attribute of the link tag specifies that the browser should preemptively establish a connection to the external domain specified by the href attribute.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fuploads%2Ffavicon-wp-300x300.png"&gt;
          coding.courses
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>preconnect</category>
      <category>html</category>
      <category>rel</category>
    </item>
    <item>
      <title>HTML &lt;link rel="dns-prefetch"&gt;</title>
      <dc:creator>Youn</dc:creator>
      <pubDate>Tue, 01 Sep 2026 02:13:33 +0000</pubDate>
      <link>https://dev.to/code1/html-3ofd</link>
      <guid>https://dev.to/code1/html-3ofd</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;😄 This post is based on the content from &lt;a href="https://coding.courses/html-link-reldns-prefetch/" rel="noopener noreferrer"&gt;coding.courses&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Definition and Usage
&lt;/h2&gt;

&lt;p&gt;The rel="dns-prefetch" attribute of the &lt;a href="https://coding.courses/html-link-tag/" rel="noopener noreferrer"&gt;&amp;lt;link&amp;gt;&lt;/a&gt; tag specifies that the browser should preemptively perform DNS resolution for the external domain specified by the href attribute and cache IP address and other information required for connection.&lt;br&gt;
This reduces latency when the browser connects to that domain, thereby improving connection speed.&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;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"dns-prefetch"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://another-domain.com"&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;The rel="dns-prefetch" attribute of the &amp;lt;link&amp;gt; tag is used to improve connection speed when the current web page needs to connect to external domains.&lt;br&gt;
There are many cases where a web page needs to connect to external domains.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When connecting to Google's service domain to use web fonts provided by Google&lt;/li&gt;
&lt;li&gt;When connecting to the corresponding domain to add external libraries or scripts to a web page&lt;/li&gt;
&lt;li&gt;When using externally hosted images or media on a web page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In these cases, using &amp;lt;link rel="dns-prefetch"&amp;gt;&lt;br&gt;
can improve page loading speed by allowing the page to connect to the corresponding external domains more quickly.&lt;/p&gt;
&lt;h2&gt;
  
  
  Usage Notes
&lt;/h2&gt;
&lt;h3&gt;
  
  
  # DNS Resolution for a Domain
&lt;/h3&gt;

&lt;p&gt;Users remember websites by domain names, but servers identify them by IP addresses.&lt;br&gt;
This is why DNS (Domain Name System) exists.&lt;br&gt;
Browsers use DNS to convert a domain name into its corresponding IP address. This process is performed first when connecting to a domain. For example, suppose you link a CSS file provided by Google to use web fonts on your page. This file is located at an external domain path, &lt;a href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital@0;1&amp;amp;display=swap" rel="noopener noreferrer"&gt;https://fonts.googleapis.com/css2?family=Roboto+Mono:ital@0;1&amp;amp;display=swap&lt;/a&gt;.&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;head&amp;gt;&lt;/span&gt;
    ...
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.googleapis.com/css2?family=Roboto+Mono:ital@0;1&amp;amp;display=swap"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    ...
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Using &amp;lt;link rel="dns-prefetch"&amp;gt;&lt;br&gt;
performs DNS resolution for the linked domain in advance and caches IP address and other information required for connection, saving DNS resolution time for the domain.&lt;/p&gt;
&lt;h3&gt;
  
  
  # How to Implement
&lt;/h3&gt;

&lt;p&gt;The simplest way to implement rel="dns-prefetch" with the &amp;lt;link&amp;gt; tag is to add the &amp;lt;link&amp;gt; tag to the document's &amp;lt;head&amp;gt; tag.&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;head&amp;gt;&lt;/span&gt;
    ...
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"dns-prefetch"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.googleapis.com"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://fonts.googleapis.com/css2?family=Roboto+Mono:ital@0;1&amp;amp;display=swap"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    ...
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This allows the browser to perform DNS resolution required to load Google web fonts in advance, which can improve page loading speed.&lt;br&gt;
You can repeat the above code for each external domain you want to connect to.&lt;/p&gt;
&lt;h3&gt;
  
  
  # Important Considerations
&lt;/h3&gt;
&lt;h4&gt;
  
  
  - Not Supported by All Browser
&lt;/h4&gt;

&lt;p&gt;The rel="dns-prefetch" attribute of the &amp;lt;link&amp;gt; tag is supported by many modern browsers, but it may not be supported by older browsers or some browsers.&lt;/p&gt;
&lt;h4&gt;
  
  
  - Do Not Overuse
&lt;/h4&gt;

&lt;p&gt;Using the rel="dns-prefetch" attribute of the &amp;lt;link&amp;gt; tag for all external domains is not recommended. It should only be used when necessary. Excessive DNS lookups can consume unnecessary resources. This unnecessary resource consumption can cause the browser to operate inefficiently. In general, you should try not to perform more than 10 DNS lookups.&lt;/p&gt;
&lt;h4&gt;
  
  
  - Do Not Apply to Unused External Domains
&lt;/h4&gt;

&lt;p&gt;Do not use it for external domains that are not even used on the current page.&lt;br&gt;
This is simply wasteful and only causes unnecessary resource consumption by performing DNS lookups for domains that are not actually needed. This can cause the browser to operate inefficiently.&lt;/p&gt;
&lt;h4&gt;
  
  
  - rel="dns-prefetch" Can Only Be Used With the &amp;lt;link&amp;gt; Tag
&lt;/h4&gt;

&lt;p&gt;The rel="dns-prefetch" attribute can only be used with the &amp;lt;link&amp;gt; tag.&lt;/p&gt;
&lt;h4&gt;
  
  
  - Performance Improvement May Be Minimal.
&lt;/h4&gt;

&lt;p&gt;The rel="dns-prefetch" attribute of the &amp;lt;link&amp;gt; tag can help improve web page loading speed, but the actual perceived speed improvement may be minimal. In particular, the effect may not be significant when the user's internet connection speed is slow or when the web page size is large.&lt;/p&gt;
&lt;h2&gt;
  
  
  References
&lt;/h2&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://coding.courses/html-link-reldns-prefetch/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fthemes%2Fcodingeverybody-en%2Fassets%2Fimages%2Fbranding%2Fsocial-share_img.png" height="420" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://coding.courses/html-link-reldns-prefetch/" rel="noopener noreferrer" class="c-link"&gt;
            HTML &amp;lt;link rel="dns-prefetch"&amp;gt; – Proper Understanding and Usage - codingCourses
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            The rel="dns-prefetch" attribute of the link tag specifies that the browser should preemptively perform DNS resolution for the external domain specified by the href attribute and cache IP address and other information required for connection.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcoding.courses%2Fwp-content%2Fuploads%2Ffavicon-wp-300x300.png" width="300" height="300"&gt;
          coding.courses
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>prefetch</category>
      <category>rel</category>
      <category>html</category>
    </item>
  </channel>
</rss>
