<?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: Trevor Bruner</title>
    <description>The latest articles on DEV Community by Trevor Bruner (@tbruner).</description>
    <link>https://dev.to/tbruner</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F659939%2F4d7cbfae-8dc8-4cdf-99b0-52ebd54cf11c.jpeg</url>
      <title>DEV Community: Trevor Bruner</title>
      <link>https://dev.to/tbruner</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tbruner"/>
    <language>en</language>
    <item>
      <title>What are CSS Variables?</title>
      <dc:creator>Trevor Bruner</dc:creator>
      <pubDate>Thu, 06 Jan 2022 01:27:08 +0000</pubDate>
      <link>https://dev.to/tbruner/what-are-css-variables-2eae</link>
      <guid>https://dev.to/tbruner/what-are-css-variables-2eae</guid>
      <description>&lt;p&gt;CSS variables, also known as custom properties(official name) or cascading variables, are a useful CSS feature that allows you to set a value once and reference it many times throughout an HTML document. As with other programming languages, variables are a valuable tool that helps reduce redundant tasks and hold values that can be used or changed later. CSS variables were introduced in 2016 with the release of Chrome 49, and are now supported across all modern web browsers with the exception of Internet Explorer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use CSS Variables?
&lt;/h2&gt;

&lt;p&gt;It will make writing and maintaining your CSS easier. Most websites have a color palette that is repeated throughout. Now imagine you have a website and want to change the color palette. In a complex website you'd have to update the colors in the many places it's used. That is a tedious task that no one wants to do. With CSS variables you'd only have to update the colors in once. It doesn't just have to be colors either, any CSS style that is repeated can take advantage of this. Not only that but variables make your CSS easier to read. It's much easier to understand CSS that has descriptive variable names than one with values set individually.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use CSS Variables
&lt;/h2&gt;

&lt;p&gt;Setting a variable is just like setting a CSS property. The only difference is you use a custom variable name which must be prefixed with double hyphens (--). Note that CSS variables are case sensitive meaning &lt;code&gt;--main&lt;/code&gt; is not the same as &lt;code&gt;--MAIN&lt;/code&gt;.&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;--name&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;value&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To reference a variable use the &lt;code&gt;var()&lt;/code&gt; function.&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;var&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;--name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;fallback&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;name&lt;/code&gt; is the variable name and &lt;code&gt;fallback&lt;/code&gt; is an optional value that will be used if the variable is invalid. The &lt;code&gt;var()&lt;/code&gt; function only accepts two arguments. Anything following the first comma is taken as the fallback value. However you can still define multiple fallback values.&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;var&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;--name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;red&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;black&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here &lt;code&gt;red, black&lt;/code&gt; is the second argument and will be used just the same as if you were to just define red as the value and black as the first fallback. If you decide to used another variable as a fallback you cannot do the following:&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;var&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;--name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;--fallback-var&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would be invalid as &lt;code&gt;--fallback-var&lt;/code&gt; would be used and has no value when used outside the first argument of the &lt;code&gt;var()&lt;/code&gt; function. Instead you would need to do the following:&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;var&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;--name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;var&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;--fallback-var&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a valid way to define a variable as a fallback to another variable, but be warned as this can cause performance issues as it takes more time to parse variables. &lt;/p&gt;

&lt;p&gt;If a variable name is invalid with no fallback the property will be set to the default value or inherited value. This may cause styling issues that make your page less accessible or difficult to parse. For example you may have a dark mode and a variable for the font color. If that variable is invalid the font color will default to black(or the inherited value). Now the text is going to be very difficult or impossible to read. While most modern browsers support CSS variables, there are users that may access your page from Internet Explorer or an older browser. There's also human error, you don't want a typo to break the styling of your page. For these reasons it's good practice to include a fallback.&lt;/p&gt;

&lt;p&gt;CSS variables are typically set in the &lt;code&gt;:root&lt;/code&gt; pseudo-class as it gives the variable a global scope and thus can be used throughout the document. If you need to you can set a variable anywhere in the document but it will only be accessible within that element's local scope.&lt;/p&gt;

&lt;p&gt;Here's a short example of how you might use CSS variables:&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="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--heading-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--paragraph-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;indigo&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;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--heading-color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--paragraph-color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;#highlight&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--heading-color&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the variables &lt;code&gt;--heading-color&lt;/code&gt; and &lt;code&gt;--paragraph-color&lt;/code&gt; are set under the &lt;code&gt;:root&lt;/code&gt; selector which gives them a global scope. The &lt;code&gt;--heading-color&lt;/code&gt; variable is then used as the color value for the &lt;code&gt;h1&lt;/code&gt; selector and the &lt;code&gt;highlight&lt;/code&gt; id, and the &lt;code&gt;--paragraph-color&lt;/code&gt; is used as the color value for the &lt;code&gt;p&lt;/code&gt; selector.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Variables in JavaScript
&lt;/h2&gt;

&lt;p&gt;Yes, you can get and set CSS variables in JavaScript. To get a variable value use the &lt;code&gt;.getPropertyValue()&lt;/code&gt; method. To set a variable value use the &lt;code&gt;.setProperty()&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// get root element&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;root&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="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;:root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// get my-var value&lt;/span&gt;
&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getPropertyValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--my-var&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// set my-var value to green&lt;/span&gt;
&lt;span class="nx"&gt;root&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--my-var&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Common Use Cases
&lt;/h2&gt;

&lt;p&gt;I won't go into too much detail on these, but here are a few common use cases for CSS variables.&lt;/p&gt;

&lt;h3&gt;
  
  
  Theming
&lt;/h3&gt;

&lt;p&gt;If you want different themes for your website, such as dark/light mode, you can use a set of variables that you change for each theme. The following is a simple example of how you could implement a dark/light mode feature with CSS and JavaScript.&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="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--bg-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.dark-mode&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--bg-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--text-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;darkModeSwith&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="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#switch&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;darkModeSwith&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toggle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dark-mode&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Media Queries
&lt;/h3&gt;

&lt;p&gt;Responsiveness is important in the current world of web development and variables with media queries makes this much easier to achieve. You could do the following and the margin size will change when the screen width is less than 600px.&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="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;25px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;screen&lt;/span&gt; &lt;span class="n"&gt;and&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;600px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Size and Space Elements Relative to Each Other
&lt;/h3&gt;

&lt;p&gt;You can use the &lt;code&gt;calc()&lt;/code&gt; function along with CSS variables to easily set things relative to each other. If you wanted to make your heading twice the size of your paragraph font you could do the following.&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="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--paragraph-font&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;14px&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="n"&gt;calc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--paragraph-font&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="err"&gt;*&lt;/span&gt; &lt;span class="m"&gt;2&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;
  
  
  More CSS variables
&lt;/h2&gt;

&lt;p&gt;Interested in learning more about CSS variables? Check out the following pages I used for reference:&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties"&gt;Mozilla Web Docs&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developers.google.com/web/updates/2016/02/css-variables-why-should-you-care"&gt;Google Developers&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.lambdatest.com/blog/guide-to-css-variables-with-examples/"&gt;Lambda Test&lt;/a&gt;&lt;br&gt;
&lt;a href="https://devdocs.io/css/using_css_custom_properties"&gt;CSS Docs&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Introduction to HTML</title>
      <dc:creator>Trevor Bruner</dc:creator>
      <pubDate>Wed, 06 Oct 2021 18:12:10 +0000</pubDate>
      <link>https://dev.to/tbruner/introduction-to-html-m8n</link>
      <guid>https://dev.to/tbruner/introduction-to-html-m8n</guid>
      <description>&lt;h2&gt;
  
  
  What is HTML?
&lt;/h2&gt;

&lt;p&gt;HTML stands for HyperText Markup Language and is the standard language for structuring web pages. A HTML document is essentially a series of elements, each with an identify tag. These tags give meaning to HTML elements. Some examples include paragraphs, headings, and lists. HTML only provides page structure thus it is often used alongside other technologies like CSS and JavaScript that provide styling and interactivity.&lt;/p&gt;

&lt;h3&gt;
  
  
  HTML Elements
&lt;/h3&gt;

&lt;p&gt;What is a HTML element? Well to answer that question lets look an example:&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;Hello World&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;This is an example of a paragraph element. This element is composed with an opening tag &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;, a closing tag &lt;code&gt;&amp;lt;/p&amp;gt;&lt;/code&gt;, and the content &lt;code&gt;Hello World&lt;/code&gt;. As you may have noticed the opening tag is composed of the element name (in this case &lt;code&gt;p&lt;/code&gt; for paragraph) enclosed in angle brackets. The closing tag is similar to the opening tag but contains a forward slash following the opening angle bracket. The content goes in between the opening and closing tags and can include other elements or, in this case, text.&lt;/p&gt;

&lt;p&gt;Elements can also have attributes like in the example below:&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;"greeting"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello World&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;This example is similar to the previous but it has &lt;code&gt;class="greeting"&lt;/code&gt; in the opening tag. In this case class is the attribute and "greeting" is the value. Attributes like this one provide more information about the element that we don't want to appear. This information is useful when using JavaScript and CSS to select elements, and for making web pages more accessible as it is used by screen readers to identify content.&lt;/p&gt;

&lt;p&gt;We need more than just the paragraph element to create a web page. Below are a few common HTML elements with a short explanation:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt; - This is the root element and thus contains all other elements.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; - Contains information about the page like the title and links to imported files like CSS.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; - Contains all the visible content on the page.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;h1&amp;gt; - &amp;lt;h6&amp;gt;&lt;/code&gt; - Headings ranging from 1 to 6 with 1 being the highest level and one typically used for the main title.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; - Defines a paragraph.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; - The anchor element is used to define links. The &lt;code&gt;href&lt;/code&gt; attribute contains a link to another resource, usually a URL.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; - A generic block level element often used to group elements or when there isn't a more descriptive element to use.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; - A generic inline element often used to style a portion of inline content.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt; - Defines the documents title that typically displays in the browsers title bar or tab. It is a required element and can only be defined once.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;article&amp;gt;&lt;/code&gt; - Defines an article.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; - Defines an image. The attribute &lt;code&gt;src&lt;/code&gt; is used to define the path to an image. The attribute &lt;code&gt;alt&lt;/code&gt; is used to give a short description of an image. Though optional, the &lt;code&gt;alt&lt;/code&gt; attribute should always be used as it will display when an image doesn't load and used by screen readers to identify an image. This improves user experience and accessibility.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;ol&amp;gt; &amp;lt;ul&amp;gt; &amp;lt;li&amp;gt;&lt;/code&gt; - Used to define lists. &lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt; defines an ordered list, &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; defines an unordered list, and &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; individual list items.&lt;/p&gt;

&lt;p&gt;There are many more but this should be enough to get you started.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simple Example
&lt;/h2&gt;

&lt;p&gt;Now that we understand what HTML is let's look at a simple example.&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="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&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;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="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Document&lt;span class="nt"&gt;&amp;lt;/title&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="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Heading&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;paragraph&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ol&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Item One&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;Item Two&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ol&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;p&gt;The first tag we see here is &lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/code&gt; which is a required declaration that tells the browser the document type is HTML. Following that we have the root &lt;code&gt;html&lt;/code&gt; tag with the attribute &lt;code&gt;lang="en"&lt;/code&gt;. Here the &lt;code&gt;lang&lt;/code&gt; attribute sets the language to English with the value &lt;code&gt;en&lt;/code&gt;. The language attribute can be defined in any element but should always be defined in the &lt;code&gt;html&lt;/code&gt; tag. Defining the language of your content allows you to style it differently based on the language.&lt;/p&gt;

&lt;p&gt;Next we have the &lt;code&gt;head&lt;/code&gt; element and it contains two &lt;code&gt;meta&lt;/code&gt; elements and the &lt;code&gt;title&lt;/code&gt; element. The first &lt;code&gt;meta&lt;/code&gt; tag contains the attribute &lt;code&gt;charset="UTF-8"&lt;/code&gt;. This simply specifies the character encoding of the document. While the browser will define the character encoding if this is omitted HTML does not. So it's important to include it to ensure your page displays correctly. The character encoding &lt;code&gt;UTF-8&lt;/code&gt; is used as it provides access to almost all characters and symbols. The second &lt;code&gt;meta&lt;/code&gt; tag contains the attributes &lt;code&gt;name="viewport"&lt;/code&gt; and &lt;code&gt;content="width=device-width, initial-scale=1.0"&lt;/code&gt;. These collectively define the viewport based on the device width. I won't get into the details here, but these attributes are necessary to style a page differently based on the device width.&lt;/p&gt;

&lt;p&gt;The body tag is last and contains &lt;code&gt;heading&lt;/code&gt;, &lt;code&gt;paragraph&lt;/code&gt;, and &lt;code&gt;ol&lt;/code&gt; elements.&lt;/p&gt;

&lt;p&gt;That completes the basic structure of a HTML document.&lt;/p&gt;

&lt;p&gt;Thank you for reading!&lt;/p&gt;

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