<?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: Babatunde Sulyman </title>
    <description>The latest articles on DEV Community by Babatunde Sulyman  (@sulyman1020).</description>
    <link>https://dev.to/sulyman1020</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%2F1107687%2F09128e7a-652e-47e5-b0ba-358914e20042.png</url>
      <title>DEV Community: Babatunde Sulyman </title>
      <link>https://dev.to/sulyman1020</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sulyman1020"/>
    <language>en</language>
    <item>
      <title>How to build a Piano With CSS.</title>
      <dc:creator>Babatunde Sulyman </dc:creator>
      <pubDate>Sat, 14 Oct 2023 17:29:39 +0000</pubDate>
      <link>https://dev.to/sulyman1020/how-to-build-a-piano-with-css-2m68</link>
      <guid>https://dev.to/sulyman1020/how-to-build-a-piano-with-css-2m68</guid>
      <description>&lt;p&gt;The tech world is swarmed with many developers ranging from different stacks with the possibility of getting jobs from companies becomes extremely thin.&lt;/p&gt;

&lt;p&gt;To get a job, the core requirement often asked by the recruiter is a portfolio which looks something like this:  a blank portfolio meets rejection or is tossed to the bin or not attended to at all. &lt;/p&gt;

&lt;p&gt;The first step to take as a developer is to have a standard portfolio that contains a list of outstanding projects to showcase your potential to the hirer(recruiter) when hiring. &lt;/p&gt;

&lt;p&gt;There are many web development languages to build a project, like JavaScript, Python, etc., but we will be using CSS in this tutorial as it's the simplest to use.&lt;/p&gt;

&lt;h1&gt;
  
  
  What's CSS
&lt;/h1&gt;

&lt;p&gt;CSS (cascading style sheets) is a language that allows you to customize your HTML document. HTML document constructs your website structure, and CSS styles the interior decoration of a  website as you want. With CSS, your website has the following:&lt;/p&gt;

&lt;p&gt;● An appealing design.&lt;br&gt;
● Proper layout.&lt;br&gt;
● Responsiveness (a web page that looks good on mobile and desktop devices.)&lt;/p&gt;

&lt;p&gt;In this tutorial, you will learn how to build a piano with CSS in a few steps.&lt;/p&gt;
&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;For you to follow along with the article, you must have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A basic understanding of HTML as there would be a revision on some HTML elements, If not, you can check this to revise your learning.&lt;/li&gt;
&lt;li&gt;You also need a text editor and an image for the project.  You can download the image through this &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NGoFMrDY--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ivb6hj61b6ntuo70lt4z.png" rel="noopener noreferrer"&gt;link&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  Table of Content
&lt;/h1&gt;

&lt;p&gt;&lt;a href="//Choosing%20a%20text%20editor."&gt;Choosing a text editor.&lt;/a&gt;&lt;br&gt;
&lt;a href="//How%20to%20get%20started."&gt;Choosing a text editor.&lt;/a&gt;&lt;br&gt;
&lt;a href="//Linking%20CSS%20to%20HTML%20file."&gt;Linking CSS to HTML file.&lt;/a&gt;&lt;br&gt;
&lt;a href="//The%20project."&gt;The project.&lt;/a&gt;&lt;br&gt;
&lt;a href="https://dev.toResources"&gt;Resources&lt;/a&gt;.&lt;br&gt;
&lt;a href="https://dev.toConclusion"&gt;Conclusion&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Choosing a Text Editor
&lt;/h3&gt;

&lt;p&gt;First, before you start writing the code, you need to have a working text editor, i.e. a code editor. If you have installed your text editor, launch it and click the workspace navigation bar. It should show something like this:&lt;/p&gt;

&lt;p&gt;I’m using VS code, and this is my setup page&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fheii0oibrusjt2m92q5q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fheii0oibrusjt2m92q5q.png" alt="vs image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The best way to enjoy coding is to see what you are building live. For that, You will need to install an extension called “live server” on the VS code. A live server refreshes the web page when you make changes to your HTML file/CSS file.&lt;/p&gt;

&lt;p&gt;To add a live server, follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Tap the icon extension on the right side of the VS code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpp2z3mwt6pczbkfm9wm1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpp2z3mwt6pczbkfm9wm1.jpg" alt="icon image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Search for the live server and install it. &lt;/li&gt;
&lt;li&gt; Go back to your html file and choose “open with live server” from the menu. Or press alt+l+alt+O.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Your webpage is ready to be seen in your browser.&lt;/p&gt;
&lt;h1&gt;
  
  
  How to Get Started
&lt;/h1&gt;
&lt;h2&gt;
  
  
  Create a folder
&lt;/h2&gt;

&lt;p&gt;As the heading implies, you need to create a unique folder where your code files will sit. The two files are HTML and CSS files for this project. With this setting, the files are separated, and you can debug your code in peace.&lt;br&gt;
You can use "Piano project," as the folder name.&lt;/p&gt;

&lt;p&gt;Inside the folder, create the two files mentioned above. If you are uncertain, type index.html (for the first file) and style.css (for the second file). &lt;br&gt;
Remember to check your spelling.&lt;/p&gt;

&lt;p&gt;You are getting closer!&lt;br&gt;
Your project setup should look similar to this if you are using VS code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgahsya19iu7vtjrga0ll.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgahsya19iu7vtjrga0ll.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Linking CSS to an HTML file
&lt;/h2&gt;

&lt;p&gt;Although you may embed your CSS codes inside an HTML file (either internal or inline CSS), that invites rough work. The goal is to have clean and readable documentation. To achieve that, we will be using external CSS which allows us to make multiple changes to our HTML elements (webpages).&lt;/p&gt;

&lt;p&gt;The external CSS has to be linked for it to work.&lt;br&gt;
To do that, copy the code below, then paste it within your &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; element in your html file.&lt;/p&gt;

&lt;p&gt;Open the &lt;code&gt;index.html&lt;/code&gt; file and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;link  rel="stylesheet"  href="style.css"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;_ An external CSS nested in an HTML file_     &lt;/p&gt;

&lt;h3&gt;
  
  
  The Project
&lt;/h3&gt;

&lt;p&gt;You will set the piano structure with HTML and style it with CSS. Remember that our content should be in the body element.&lt;/p&gt;

&lt;p&gt;The Piano’s structure is in a few steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; &lt;strong&gt;Create a container for the Piano keys&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;How do you create a container? You can use the &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; element as a container that serves as:&lt;br&gt;
● A division from other common semantic elements.&lt;br&gt;
● As a parent for its child elements.&lt;br&gt;
● A container.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;div&lt;/strong&gt; element is now serving as your Piano where its keys (children) will be.&lt;/p&gt;

&lt;p&gt;To separate the div from other elements, give it an  #ID selector with the name “piano.”&lt;br&gt;
Write the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div id="piano"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few things to know:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; The &lt;strong&gt;div&lt;/strong&gt; has the &lt;strong&gt;Id&lt;/strong&gt; attribute with the name Piano.&lt;/li&gt;
&lt;li&gt; To create an &lt;strong&gt;Id&lt;/strong&gt;, type the word &lt;strong&gt;Id&lt;/strong&gt;, followed by the equal sign, and quotation marks.&lt;/li&gt;
&lt;li&gt; The &lt;strong&gt;ID&lt;/strong&gt; attribute accepts a unique name.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: Add an image&lt;br&gt;
Go and embed the image link provided at the beginning of this tutorial to your html image tag.&lt;br&gt;
Like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="https://cdn.freecodecamp.org/platform/universal/fcc_primary.svg" alt="freecodecamp logo" class="logo"&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To add an image, you must have:&lt;/p&gt;

&lt;p&gt;An HTML image tag that starts with an opening tag; the greater than sign(&amp;lt;), has an &lt;strong&gt;SRC&lt;/strong&gt; attribute; defines the path of the image, an &lt;strong&gt;Alt&lt;/strong&gt; Attribute; the alternative name to the image when the page is loading or the browser can't fetch the image source and no closing tag.&lt;br&gt;
Note:&lt;/p&gt;

&lt;p&gt;● &lt;strong&gt;Img&lt;/strong&gt;: stands for an image&lt;br&gt;
● &lt;strong&gt;Src&lt;/strong&gt;:  is a source for the image&lt;br&gt;
● &lt;strong&gt;Alt&lt;/strong&gt;: means the Alternative name of the image&lt;/p&gt;

&lt;p&gt;Step 3: The Piano’s keys&lt;/p&gt;

&lt;p&gt;The Piano must-have keys, without the keys, there is no Piano. After the image element, add a div with a class of keys. Within the .keys element, nest seven div elements with the class name "Key”:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&amp;lt;div class="keys"&amp;gt;
    &amp;lt;div class="key"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="key"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="key"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="key"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="key"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="key"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="key"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note:&lt;br&gt;
● The div .keys is the parent.&lt;br&gt;
● The keys element holds seven div elements&lt;br&gt;
● The seven div elements are your piano keys.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;class&lt;/strong&gt; attribute, unlike the &lt;strong&gt;#Id&lt;/strong&gt;, accepts more values (names). Before the next step, you need to separate the black key from the white key. Add “black--key” to the second, third, fifth, sixth, and seventh “key” elements you created.&lt;/p&gt;

&lt;p&gt;Write this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="key "&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note:&lt;br&gt;
● The class attribute takes many values.&lt;br&gt;
● There must be a space between the first and second values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Copy and paste&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To round off the Piano’s structure, copy and paste the seven .key elements twice into the .keys div.&lt;/p&gt;

&lt;p&gt;The key elements must be 21.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="key "&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="key "&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;div class="key black--key"&amp;gt;&amp;lt;/div&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you have completed your piano structure. Open your CSS file and let's see the magic.&lt;/p&gt;

&lt;p&gt;In your HTML file, you created &lt;strong&gt;id&lt;/strong&gt; and &lt;strong&gt;class&lt;/strong&gt; selectors for the div elements. It's time to use these selectors.&lt;/p&gt;

&lt;p&gt;But do you know that:&lt;br&gt;
Everything on the web page is a box model?&lt;/p&gt;

&lt;p&gt;Why?&lt;br&gt;
This tells the browsers to add default margin and padding values to an html element. Despite that, you can reset it to fit your Piano.&lt;/p&gt;

&lt;p&gt;First, change the HTML (webpage) default box model with the &lt;code&gt;border-box&lt;/code&gt; property and give it a value of &lt;code&gt;box-sizing&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;html{
    box-sizing: border-box;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The box-sizing property respects the size of an element. It also takes new width and height values to resize the element.&lt;br&gt;
To learn more about the border box, click the link. &lt;/p&gt;

&lt;p&gt;Next, write the code below,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;*, ::before, ::after{
    box-sizing: inherit;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;br&gt;
The &lt;code&gt;*&lt;/code&gt; is a universal selector that targets all the elements on the page.&lt;br&gt;
 The &lt;strong&gt;Before&lt;/strong&gt; and &lt;strong&gt;After&lt;/strong&gt; selectors are pseudo-elements that target an element. &lt;br&gt;
The** Before** is for the first child of the selected element,&lt;br&gt;
The &lt;strong&gt;After&lt;/strong&gt; targets the last child of the selected element.&lt;br&gt;
The &lt;code&gt;*&lt;/code&gt;has the box-sizing property with a value of Inherit. &lt;br&gt;
The &lt;code&gt;*&lt;/code&gt;   is inheriting the value of the HTML &lt;strong&gt;box-sizing&lt;/strong&gt; value.&lt;/p&gt;
&lt;h2&gt;
  
  
  Style the Piano
&lt;/h2&gt;

&lt;p&gt;Give your Piano a background and some properties to see what you have been doing.&lt;br&gt;
Write the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#piano{
    background-color: #00471b;
    width: 992px;
    height: 250px;
    margin: 80px auto;
    padding: 90px 20px 0 2opx;
    position: relative;
    border-radius: 10px;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's define the above code:&lt;/p&gt;

&lt;p&gt;● &lt;strong&gt;Background -color&lt;/strong&gt;:   the background for the Piano. &lt;br&gt;
● &lt;strong&gt;Width&lt;/strong&gt;: The values for the Piano width.&lt;br&gt;
● &lt;strong&gt;Height&lt;/strong&gt;: the values for the Piano height.&lt;br&gt;
● &lt;strong&gt;Margin&lt;/strong&gt;: the values place the Piano in the center.&lt;br&gt;
● &lt;strong&gt;Padding&lt;/strong&gt;: The values create space inside the Piano. In other words, the space for the top, left, bottom, and right of the Piano.&lt;br&gt;
● &lt;strong&gt;Border-radius&lt;/strong&gt;: the four outer edges of the Piano&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Keys&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You are to use the class selector with the value "keys". This will create a container for the black and white keys.&lt;br&gt;
Copy the below code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.keys{
    background-color: #040404;
    width: 949px;
    height: 180px;
    padding-left: 2px;
    overflow: hidden;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above snippet, the &lt;code&gt;.keys&lt;/code&gt; element has:&lt;br&gt;
● A padding-left property that shifts the key element to the left side inside the Piano&lt;br&gt;
● Overflow: the value Hidden means the keys and their children will not move outside the Piano.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The key&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This creates white keys for the piano&lt;/p&gt;

&lt;p&gt;Take a look at the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
.key{
    background-color:#ffffff;
    width:41px;
    height: 175px;
    position: relative;
    margin: 2px;

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note:&lt;br&gt;
● &lt;strong&gt;Background color&lt;/strong&gt;: the value creates a white color for the keys.&lt;br&gt;
● &lt;strong&gt;Width&lt;/strong&gt;: these values place the white keys within the keys’ container.&lt;br&gt;
● &lt;strong&gt;Height&lt;/strong&gt;: the value adjusts the white keys but not above the keys’ container.&lt;br&gt;
● &lt;strong&gt;Margin&lt;/strong&gt;: this spread and put space between each white key you have.&lt;br&gt;
● &lt;strong&gt;Position&lt;/strong&gt;: the "relative" value restricts the &lt;strong&gt;white keys&lt;/strong&gt; to the .keys element i.e. the white keys are within the .keys element environment.&lt;/p&gt;

&lt;p&gt;Remember the .keys element, which you created before, is the parent of the new white keys.&lt;/p&gt;

&lt;p&gt;The position and shape of the white keys are not good-looking. These two properties will change the position and shape of the white keys.&lt;/p&gt;

&lt;p&gt;Add the below code to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Float: left;
Border-radius: 0 0 3px 3px;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check it out!&lt;br&gt;
Note:&lt;br&gt;
● &lt;strong&gt;Float&lt;/strong&gt;: this specifies how an element should be floated. It’s used when an element has a box but isn’t positioned.&lt;br&gt;
● &lt;strong&gt;Border-radius&lt;/strong&gt;: defines the outer edge of an element. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The black keys&lt;/strong&gt;&lt;br&gt;
As you have seen the white keys, let’s create a selector for the black keys. To save you time, the Pseudo selectors you prepared will create the black keys. &lt;br&gt;
See the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
.key.black--key::After{
    Content: "";
    Background-color: #1d1d22;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How did I do that?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; The pseudo selector which is set to &lt;strong&gt;AFTER&lt;/strong&gt; targets what follows the .key elements and gives it a new style.&lt;/li&gt;
&lt;li&gt; The content should be empty when you don't.&lt;/li&gt;
&lt;li&gt; The background of the element is different from the .key elements&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's continue. Position the .black—key as absolute and give it a negative value for the left.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
Position: absolute;
Left: -18px;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code takes the &lt;code&gt;.black—key&lt;/code&gt;from the &lt;code&gt;.key&lt;/code&gt; elements to the left. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The position absolute moves an element from its normal flow and places it nearest to the parent. Who is the parent? The .key selector.&lt;/li&gt;
&lt;li&gt;A position absolute must have a parent element, or else it overlaps other elements.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Include the width and height to make the black keys distinct from the white keys. Add the code below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
width: 32px;
height: 100px;
border-radius: 0 0 3px 3px;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above increases the &lt;strong&gt;black keys&lt;/strong&gt; height and width but the border radius is the same as the &lt;strong&gt;white keys&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The image of the Piano&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Set the image like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
.logo{
width: 200px;
position: absolute;
top: 23px;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above sets the image with position absolute, making it a bit lower from the top. With these steps, you have built a Piano with CSS, and you will be able to use CSS for your next project. &lt;/p&gt;

&lt;h3&gt;
  
  
  The Piano Output
&lt;/h3&gt;

&lt;p&gt;When you run this project you get this output.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo4jk5w4ubsbev1njoha1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo4jk5w4ubsbev1njoha1.png" alt="Image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;CSS is a language that formats a webpage by giving it a dynamic style as you want. In this article, we covered some CSS properties and learned how to use them. In the end, we used CSS to build a Piano.&lt;/p&gt;

&lt;p&gt;I hope you have gotten what you expected from this article. Please feel free to share your opinions by commenting below. &lt;/p&gt;

&lt;h1&gt;
  
  
  Resources
&lt;/h1&gt;

&lt;p&gt;● &lt;a href="https://dev.toDeveloper%20Mozilla"&gt; Developer Mozilla&lt;/a&gt;&lt;br&gt;
● &lt;a href="https://dev.toFreeCodeCamp"&gt;FreeCodeCamp&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>css</category>
      <category>programming</category>
    </item>
    <item>
      <title>CSS Variables: Understanding the Var() function and how to use it.</title>
      <dc:creator>Babatunde Sulyman </dc:creator>
      <pubDate>Tue, 08 Aug 2023 19:13:52 +0000</pubDate>
      <link>https://dev.to/sulyman1020/css-variables-understanding-the-var-function-and-how-to-use-it-l71</link>
      <guid>https://dev.to/sulyman1020/css-variables-understanding-the-var-function-and-how-to-use-it-l71</guid>
      <description>&lt;p&gt;Let's pretend you have one hundred lines of code in your CSS stylesheet. In the long run, you remember that the &lt;code&gt;H1&lt;/code&gt;and &lt;code&gt;p&lt;/code&gt; text color (black) is the same which distorts the color scheme of your project__ the texts are dimmed and unreadable.&lt;/p&gt;

&lt;p&gt;You would need to scroll up to change either the &lt;code&gt;H1&lt;/code&gt; or &lt;code&gt;P&lt;/code&gt; text-color value. Instead of skimming the lines to effect the change, you can use CSS Variables to change the values. &lt;/p&gt;

&lt;p&gt;A variable is a unit/name that stores a value and could be reused throughout the CSS stylesheet. &lt;/p&gt;

&lt;p&gt;Variables(also known as custom properties)are defined by a developer for ease, and to avoid repetition Of values and usage on elements.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to declare a Variable
&lt;/h1&gt;

&lt;p&gt;Variable accepts a unique name. It's important to give it a name you will remember. &lt;/p&gt;

&lt;p&gt;Variable declarations must begin with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Two dashes(--)&lt;/li&gt;
&lt;li&gt;A custom property name,&lt;/li&gt;
&lt;li&gt;A custom property value,&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

--color-name:#1b1b22;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above code, the &lt;code&gt;--color-name&lt;/code&gt; is the custom property name, while the &lt;code&gt;#1b1b22&lt;/code&gt; is the value.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Var() function
&lt;/h2&gt;

&lt;p&gt;A Var() function retrieves the value of the variable name and applies the value to whatever property you use it on. Var() function is declared with a parenthesis, followed by the custom property name.&lt;br&gt;
&lt;strong&gt;Syntax&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Background-color: var(--color-name);


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The Var() function will collect the variable name’s value to style the &lt;code&gt;Background-color&lt;/code&gt; for the given element. &lt;/p&gt;

&lt;p&gt;In this case, the Var() is looking for a value to paint the element’s background.&lt;/p&gt;

&lt;p&gt;Here is an example&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Html&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;h1&amp;gt;I accept variable to change  my color&amp;lt;/h1&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CSS&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

/* variable name: the --color-name */
    text-align: center;
    --color-name:red;


    /* use the --color-name as the h1 text color*/
    color: var(--color-name);


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Result&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0t7belixjzuq93k08fj2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0t7belixjzuq93k08fj2.png" alt="first image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above code, the &lt;code&gt;h1&lt;/code&gt; text color value is red;  the Var() retrieves the value from the --color-name  __ the variable name __ property.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Var() function arguments
&lt;/h2&gt;

&lt;p&gt;The Var() function accepts two arguments. The first argument’s value is for the element you want to style, and the second argument stands for the fallback value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Var() with no fallback value
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

background-color: var(--body-color);



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;--body-color&lt;/code&gt; is the first argument’s value. No fallback value is supplied.&lt;/p&gt;

&lt;h2&gt;
  
  
  Var() with a  fallback value
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

background-color: var(--body-color, orange);


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;--body-color&lt;/code&gt; is the first argument value; Orange is the fallback value.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note the following:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fallback is used when the browser couldn’t load the first argument value, or the value is invalid&lt;/li&gt;
&lt;li&gt;Fallback is optional.
&lt;/li&gt;
&lt;li&gt;Use the comma to separate the first and second arguments.&lt;/li&gt;
&lt;li&gt;You can also use the Var()function as the fallback value argument. To do that, use a comma to separate the var() function declaration.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is an example&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

background-color: var(--color-name),  var(--color-name);


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;background-color&lt;/code&gt; has a Var() function as the fallback value.&lt;/p&gt;

&lt;h1&gt;
  
  
  Type of variable scope
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Local variable scope&lt;/li&gt;
&lt;li&gt;Global variable scope&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Local variable scope
&lt;/h1&gt;

&lt;p&gt;The local scope variable is described in the element’s selector in the style sheet. All the above examples are locally scoped, and the variables could be used only for the nodes of the element.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

aside{
    --style-color1:#1b1b22;
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;From the above code, the &lt;code&gt;–-style-color1&lt;/code&gt; is locally scoped to the document’s &lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt; elements, which means the variable is limited to the &lt;code&gt;&amp;lt;aside&amp;gt;&lt;/code&gt; elements. &lt;/p&gt;

&lt;p&gt;The advantage of using a local scope variable is that it overrides the global variable. &lt;/p&gt;

&lt;p&gt;This means if you have two custom properties with similar names but different values, the browser will ignore the global custom property name and use the locally scoped one.  &lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

root{
--main-color:blue;
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

p{
    --main-color:brown;
    color: var(--main-color);
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above code, the &lt;code&gt;-–main-color&lt;/code&gt; with the value of brown will override the global variable in the root selector for the &lt;/p&gt;
&lt;p&gt; element.&lt;/p&gt;

&lt;p&gt;However, there is another way to style all your elements with one variable’s value. &lt;/p&gt;

&lt;h1&gt;
  
  
  Global variable scope
&lt;/h1&gt;

&lt;p&gt;The global scope is distinct because you are to declare it in the:root selector at the top of your stylesheet.  &lt;/p&gt;

&lt;p&gt;The global variable in the: root selector is the apex level in CSS.&lt;/p&gt;

&lt;p&gt;When your variables are there, you can style all the selected elements, and change the variables values. Any changes you made to a value will affect the element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Follow the steps below to create a global variable at the top of your stylesheet.&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Type a colon sign, or, simply put   : &lt;/li&gt;
&lt;li&gt;Write these four letters: root&lt;/li&gt;
&lt;li&gt;Close it with the curly braces sign i.e  {}&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is an example&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

:root{

}



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You have set the global variable scope that awaits the variable name plus its value to style your elements.&lt;/p&gt;

&lt;p&gt;To round up this tutorial, Let’s create 4 boxes to practice global variable scope.&lt;/p&gt;

&lt;p&gt;Open your html document to create the boxes, like this.&lt;br&gt;
&lt;strong&gt;Html&lt;/strong&gt; &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;section&amp;gt;
       &amp;lt;div class="box1"&amp;gt;box 3&amp;lt;/div&amp;gt;
       &amp;lt;div class="box2"&amp;gt;box 2&amp;lt;/div&amp;gt;
       &amp;lt;div class="box3"&amp;gt;Box 3&amp;lt;/div&amp;gt;
       &amp;lt;div class="box4"&amp;gt;Box 4&amp;lt;/div&amp;gt;


   &amp;lt;/section&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CSS&lt;/strong&gt; &lt;br&gt;
&lt;strong&gt;Create a container&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

section{
    display: flex;
    flex-direction:row;
    justify-content: space-between;
    background-color: black;
    margin: 2px;
    padding: 10px;
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Next, the boxes for the container&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


.box1{
    width: 250px;
    height: 250px;
    border-radius: 10px;


}
.box2{

    width: 250px;
    height: 250px;
    border-radius:  10px;

}
.box3{

    width: 250px;
    height: 250px;
    border-radius: 10px;
}
.box4{

    width: 250px;
    height: 250px;
    border-radius: 10px;

}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;When you preview the code with your live server, the browser is supposed to show the image below.&lt;/p&gt;

&lt;p&gt;Result&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwwlth28mfahz9q1k5ftu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwwlth28mfahz9q1k5ftu.png" alt="blank image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, scroll to the top of your style sheet to set the global variable scope.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

:root{
    /* insert  your custom property names and values
   */
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Inside the:root selector, add these custom property names and values.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

   --box-color1:#24242a;
   --box-color2:#454533;
   --box-color3:#fff444;
   --box-color4:#30204a;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Style each of the boxes' background-color with the above custom properties.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Like this:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Box 1&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


  background-color: var(--box-color1);


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Box 2&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


  background-color: var(--box-color2);



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Box 3&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

background-color: var(--box-color3);


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Box 4&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

background-color: var(--box-color4);


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Result&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj38rapar5b7uxmsvv2bk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj38rapar5b7uxmsvv2bk.png" alt="Last Image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The browser should display the above image when you reload it. If you don’t get the same result, check the code again and preview it.&lt;br&gt;
You may play with the box colors by changing the custom property names in the Var() declaration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important of CSS Variable:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;CSS variable is case-sensitive i.e. 
&lt;code&gt;--new-color&lt;/code&gt; is not the same as &lt;code&gt;--New-color&lt;/code&gt; for the custom property name.&lt;/li&gt;
&lt;li&gt;DRY: Instead of repeating a value, say, &lt;code&gt;#1b1b22&lt;/code&gt;, use CSS Variables to save your time.&lt;/li&gt;
&lt;li&gt;Variable value is easy to comprehend. For example, &lt;code&gt;--window-color&lt;/code&gt; is clearer than   &lt;code&gt;#773fff&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;DRY means “Don’t repeat yourself.”&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In this tutorial, You have known what CSS variable means,  the two types of variable scope, the var() function, and its arguments. I hope you learn something new today from this article. Feel free to drop your comment. &lt;/p&gt;

&lt;p&gt;Also, you can connect with me on Twitter.&lt;br&gt;
&lt;a href="https://twitter.com/bornonTuesday2?t=kS2qDpyerrXyG0NfDgRJEQ&amp;amp;s=09" rel="noopener noreferrer"&gt;Here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>css</category>
      <category>html</category>
    </item>
    <item>
      <title>Display Property in CSS: With Practical Examples</title>
      <dc:creator>Babatunde Sulyman </dc:creator>
      <pubDate>Tue, 01 Aug 2023 13:51:42 +0000</pubDate>
      <link>https://dev.to/sulyman1020/display-property-in-css-with-practical-examples-1ahl</link>
      <guid>https://dev.to/sulyman1020/display-property-in-css-with-practical-examples-1ahl</guid>
      <description>&lt;p&gt;The Layout of elements on the webpage assists the browser to position the elements at the right spot. Elements' layouts are interpreted by the display property. In HTML, elements on a webpage are boxes (rectangular) that are attributed to their default values by the browser. Each element has its special attachment in the Flow layout &lt;/p&gt;

&lt;p&gt;With CSS display property, the behavior of elements is controlled and identified.  What this means is: should the element start a new line, occupy the full space, how an element should be displayed, or have a default value given by the browser? Knowing how to use the CSS display property is important for element layout.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Display property syntax:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Display: value;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When declaring a display property for an element, CSS syntax requires a value. In other words, the value attached to the display property fixes the output result. Furthermore, this locates the individual model application of the value. &lt;br&gt;
For example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;element-name{
    display: value;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The display property has no value for the element name.&lt;br&gt;
Overview&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;A display property controls the behavior/layout of HTML elements on the webpage. It must have an element to control its layout.&lt;/p&gt;

&lt;p&gt;The syntax of the display property needs an assigned value. The value interprets what happens to the element.&lt;/p&gt;

&lt;p&gt;There are different CSS display property values, however, a few will be discussed in this tutorial and resources will be provided for the rest.&lt;/p&gt;

&lt;h3&gt;
  
  
  Values
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;None&lt;/li&gt;
&lt;li&gt;Hidden&lt;/li&gt;
&lt;li&gt;Inline&lt;/li&gt;
&lt;li&gt;Block&lt;/li&gt;
&lt;li&gt;Inline-block&lt;/li&gt;
&lt;li&gt;Flex&lt;/li&gt;
&lt;li&gt;Grid&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  None
&lt;/h3&gt;

&lt;p&gt;A display property with a value of none indicates that the element should not be displayed on the webpage. But it’s more appropriate to use the &lt;strong&gt;visibility property&lt;/strong&gt; if you want to hide the element.&lt;br&gt;
Example&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Html
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1 class="none"&amp;gt;im hidden&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;CSS
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.none{
    display: none;
    background-color: aqua;
    color: red;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The h1 text will not appear on the web page as the display property value is NONE.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hidden
&lt;/h3&gt;

&lt;p&gt;A value hidden hides the element from the webpage. A value hidden is different from the value NONE for three reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It doesn’t delete the space occupied on the page.&lt;/li&gt;
&lt;li&gt;It stores and may be reused later.&lt;/li&gt;
&lt;li&gt;It’s used with the visibility property.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Html
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h2 id="hidden"&amp;gt;im hidden&amp;lt;/h2&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;CSS
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#hidden{
    Visibility: hidden;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The h2 text is not visible yet it is there and may be reused later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inline
&lt;/h3&gt;

&lt;p&gt;A value INLINE displays an element not on a new line i.e. the element takes the available space and doesn’t encroach on other elements lines.&lt;br&gt;
Example&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Html
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;span&amp;gt;
       I AM INLINE

   &amp;lt;/span&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;CSS
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;span{
background-color:red;
display: inline;
color: black;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sUSYRJrS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oa2vm7xs4js16oxnf3pp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sUSYRJrS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oa2vm7xs4js16oxnf3pp.png" alt="Image description" width="551" height="143"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The display property value of the text (I am inline) is inline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The text doesn’t create a new line, instead, it transcends after the first paragraph.&lt;/li&gt;
&lt;li&gt;The text occupies the given space.&lt;/li&gt;
&lt;li&gt;Span is an inline element.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Block
&lt;/h3&gt;

&lt;p&gt;The value BLOCK is the opposite of INLINE. Element with the display property value of BLOCK takes the whole space, and start on a new line. If there are block-level elements, the value will stack them after each other.&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Html
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p id="item1"&amp;gt;
        Lorem ipsum dolor sit amet consectetur, adipisicing elit.
         Assumenda voluptatem veritatis asperiores Lorem ipsum, dolor sit amet consectetur adipisicing elit. Voluptatum perspiciatis quae, iure quia nesciunt, et aperiam temporibus nisi, cum iste dolorum doloribus tenetur sequi dolor dicta praesentium adipisci distinctio laboriosam nihil ratione. Eligendi totam deserunt unde dignissimos. Nam, modi expedita?
    &amp;lt;/p&amp;gt;
    &amp;lt;p id="item2"&amp;gt; Lorem ipsum dolor sit amet consectetur, 
        adipisicing elit. Necessitatibus exercitationem 
        ex distinctio eum porro soluta eligendi tempore n
        emo harum sed nihil esse commodi sunt totam tenetur asperiores facere de
        bitis mollitia accusantium amet, eos cupiditate corporis dolore laudantium. H
        arum, amet consectetur?&amp;lt;/p&amp;gt;
        &amp;lt;p id="item3"&amp;gt; Lorem ipsum dolor sit amet consectetur, 
            adipisicing elit. Necessitatibus exercitationem 
            ex distinctio eum porro soluta eligendi tempore n
            emo harum sed nihil esse commodi sunt totam tenetur asperiores facere de
            bitis mollitia accusantium amet, eos cupiditate corporis dolore laudantium. H
            arum, amet consectetur?&amp;lt;/p&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;CSS
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#item1{
background-color: red;
display: block;
color: black;

}
#item2{
    background color:purple;
    display: block;
    color: orange-red;

    }
    #item3{
        background-color: blue;
        display: block;
        color: pink;

        }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZYnbdQxu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9bg9p7u55yrn4u0vuisw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZYnbdQxu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9bg9p7u55yrn4u0vuisw.png" alt="Image description" width="548" height="246"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The three paragraphs__ item1, item2, item3_ have a value of BLOCK.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The paragraphs start on a new line.&lt;/li&gt;
&lt;li&gt;The first item, the second item, and the third item take their spaces.&lt;/li&gt;
&lt;li&gt;P is a BLOCK-LEVEL element.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Differences between inline and block elements
&lt;/h3&gt;

&lt;p&gt;• Inline elements: The element's width and height are not respected by the browser except if specified, still no effect. &lt;/p&gt;

&lt;p&gt;block elements: the browser gives the block elements default width and height.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Inline elements: The elements can’t contain block element. &lt;br&gt;
block elements: The elements can contain inline and some elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inline elements: The elements have no top and bottom margin.&lt;br&gt;
block elements:The elements have top and bottom margin&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inline elements: Inline elements begin not on a new line&lt;br&gt;
on the other hand, Block elements begin on a new line&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Inline elements: Examples:&lt;br&gt;
&lt;code&gt;&amp;lt;a&amp;gt; &amp;lt;link&amp;gt;&amp;lt;button&amp;gt;&amp;lt;ul&amp;gt;&amp;lt;span&amp;gt;&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Block elements: Examples:&lt;br&gt;
&lt;code&gt;&amp;lt;div&amp;gt;&amp;lt;p&amp;gt;&amp;lt;section&amp;gt;&amp;lt;form&amp;gt;&amp;lt;fieldset&amp;gt;&amp;lt;h1-h6&amp;gt; &amp;lt;header&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Assuming you have inline block-level elements on the webpage, the layout will look this like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--22wQ-AK5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6l3oq9sk9jl4gkyqgs55.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--22wQ-AK5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6l3oq9sk9jl4gkyqgs55.png" alt="Image description" width="556" height="163"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The block elements stack above each other but the inline element, which is BUTTON, stays where we put it and don’t take the whole space.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inline-block
&lt;/h3&gt;

&lt;p&gt;Display an element that performs as an inline element. The key points to know are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;That the element will have a width and height&lt;/li&gt;
&lt;li&gt;The top and bottom margins are seen.&lt;/li&gt;
&lt;li&gt;The padding works with the inline-block&lt;/li&gt;
&lt;li&gt;The element sits next to other elements like inline elements&lt;/li&gt;
&lt;li&gt;All these don’t work with the value in the line.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Html
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;a href="button"&amp;gt;button&amp;lt;/a&amp;gt;
&amp;lt;a href="button"&amp;gt;button&amp;lt;/a&amp;gt;
&amp;lt;a href="button"&amp;gt;button&amp;lt;/a&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;CSS
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a{
display: inline-block;
width: 100px;
height: 20px;
background-color: black;
color: white;
text-align: center;
text-decoration: none;
padding: 0;
margin: 20px;

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;p&gt;Figure 1 links element with a display property value of inline-block:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5sg_MExF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l07p85kn7mh4wkaegltd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5sg_MExF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l07p85kn7mh4wkaegltd.png" alt="Image description" width="359" height="102"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The three links elements are inline but we turn them to inline-block.&lt;/p&gt;

&lt;h3&gt;
  
  
  Flex
&lt;/h3&gt;

&lt;p&gt;A value flex displays an element as a block-level flex-box model. Flex-box position an element plus the content one-dimensionally_ on a row axis. &lt;br&gt;
Example&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Html
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
    &amp;lt;div&amp;gt;item 1&amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;item 2&amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;item 3&amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;CSS
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container{
    display: flex;
    background: light slate gray;
    width:300px;
    height: 300px;

}
div{
    background: red;
    width:50%;
    height: 10%;
    margin: 2px;
    padding: 10px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N1vuA6So--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3y4wn2zfiufg4nxwpfv3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N1vuA6So--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3y4wn2zfiufg4nxwpfv3.png" alt="Image description" width="408" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The value flex lays the items on a row axis.&lt;br&gt;
Read to know more about &lt;a href="https://codesweetly.com/category/flexbox"&gt;Flex-box&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Grid
&lt;/h3&gt;

&lt;p&gt;A value grid displays an element as a block-level grid container. Grid repositions an element two-dimensionally_ on a column and row axis.&lt;br&gt;
Example&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Html
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
    &amp;lt;div&amp;gt; grid item 1&amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;grid item 2&amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;grid item 3&amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt; grid item 4&amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;grid item 5&amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;grid item 6&amp;lt;/div&amp;gt;

    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Css
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.container{
    display: grid;
    grid-template-columns:1fr 1fr 1fr;
    grid-template-rows: auto auto auto;

    background: lightslategray;

    margin: 10px;
    padding: 45px;

}
div{
    background-color: dark cyan;
    color: white;
    margin: 5px;
    padding: 10px;
    border-radius: 4px;

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZMLavX44--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ukwohzd1npi8w3rzdlhm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZMLavX44--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ukwohzd1npi8w3rzdlhm.png" alt="Image description" width="550" height="190"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The value grid allows us to create three columns and three rows.&lt;/p&gt;

&lt;p&gt;Read to know more about CSS grid &lt;a href="https://www.freecodecamp.org/news/complete-guide-to-css-grid/#what-is-css-grid-s-grid-template-rows-property"&gt;grid&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Display property controls the behavior of elements on a webpage. In this article, we covered some display properties and learned how to use them. &lt;/p&gt;

&lt;p&gt;I hope you have gotten what you expect from this article. Please feel free to share your opinions by commenting below. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resources&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.w3schools.com/cssref/pr_class_display.php"&gt;Display properties&lt;/a&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/display"&gt;Display properties&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
      <category>css</category>
    </item>
  </channel>
</rss>
