<?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: Cindy Kandie</title>
    <description>The latest articles on DEV Community by Cindy Kandie (@cindykandie).</description>
    <link>https://dev.to/cindykandie</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%2F439924%2F67a379d6-6ae8-4ed7-98e0-f2ded7da10c1.png</url>
      <title>DEV Community: Cindy Kandie</title>
      <link>https://dev.to/cindykandie</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cindykandie"/>
    <language>en</language>
    <item>
      <title>CSS Animations and Transitions: Quick Guide</title>
      <dc:creator>Cindy Kandie</dc:creator>
      <pubDate>Sat, 20 Jul 2024 01:34:23 +0000</pubDate>
      <link>https://dev.to/cindykandie/css-animations-and-transitions-quick-guide-352m</link>
      <guid>https://dev.to/cindykandie/css-animations-and-transitions-quick-guide-352m</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;CSS animations and transitions are powerful tools that can bring your web pages to life. They allow you to create smooth, engaging, visually appealing effects that enhance the user experience. Whether you're looking to add simple transitions between states or complex animations that capture attention, understanding the basics of these features is essential. In this guide, we'll cover &lt;strong&gt;how to create a fade-in effect&lt;/strong&gt;, the &lt;strong&gt;difference between CSS transitions and animations, create an infinite keyframe animation&lt;/strong&gt;, &lt;strong&gt;delay the start of a transition&lt;/strong&gt;, and &lt;strong&gt;use animation timing functions to create a bounce effect&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You can interact and play with the code through the Codepens I added for each example!&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I create a fade-in effect using CSS animations?
&lt;/h3&gt;

&lt;p&gt;To create a fade-in effect, you can use the &lt;code&gt;@keyframes&lt;/code&gt; rule to define the stages of the animation. The keyframes specify the starting and ending states of the animation, and the &lt;code&gt;animation&lt;/code&gt; property applies the animation to an element. Here's an example:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/CindyCandyCode/embed/bGPpqXm?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;.fade-in&lt;/code&gt; class applies the &lt;code&gt;fadeIn&lt;/code&gt; animation over 2 seconds with an &lt;code&gt;ease-in-out&lt;/code&gt; timing function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;@keyframes fadeIn&lt;/code&gt; rule defines the animation, changing the &lt;code&gt;opacity&lt;/code&gt; from 0 to 1.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What is the difference between CSS transitions and animations?
&lt;/h3&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Used for simple state changes when an element changes from one state to another.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Require a trigger (like &lt;code&gt;:hover&lt;/code&gt;, &lt;code&gt;:focus&lt;/code&gt;, or &lt;code&gt;:checked&lt;/code&gt;) to start the transition.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Automatically interpolates the properties from the initial state to the final state.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/CindyCandyCode/embed/WNqwjeL?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this example, the background color of the &lt;code&gt;.box&lt;/code&gt; element will transition to blue over 0.5 seconds when hovered.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Used for more complex sequences of animations, involving multiple stages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Defined using &lt;code&gt;@keyframes&lt;/code&gt; and do not require a trigger to start.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Can run automatically, loop infinitely, and provide more control over timing and sequencing.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/CindyCandyCode/embed/gONrWOe?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this example, the &lt;code&gt;.rotate&lt;/code&gt; class applies a continuous rotation animation that completes one full rotation every 2 seconds.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I create a keyframe animation that runs infinitely?
&lt;/h3&gt;

&lt;p&gt;To create an animation that runs infinitely, use the &lt;code&gt;animation-iteration-count&lt;/code&gt; property with the value &lt;code&gt;infinite&lt;/code&gt;. This makes the animation loop indefinitely. Here's an example:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/CindyCandyCode/embed/zYVqwGr?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;.spin&lt;/code&gt; class will cause the element to rotate continuously, completing one full rotation every 2 seconds.&lt;/p&gt;

&lt;h3&gt;
  
  
  How can I delay the start of a CSS transition?
&lt;/h3&gt;

&lt;p&gt;To delay the start of a transition, use the &lt;code&gt;transition-delay&lt;/code&gt; property. This property specifies how long the transition should wait before starting. Here's an example:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/CindyCandyCode/embed/qBzZmOR?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this example, the background color will change to hotpink 2 seconds after the &lt;code&gt;:hover&lt;/code&gt; event is triggered, and the transition will take 0.5 seconds to complete.&lt;/p&gt;

&lt;h3&gt;
  
  
  How do I use the &lt;code&gt;animation-timing-function&lt;/code&gt; to create a bounce effect?
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;animation-timing-function&lt;/code&gt; property can be used with custom cubic-bezier values or predefined keywords to create various effects. For a bounce effect, you can define keyframes and use &lt;code&gt;ease&lt;/code&gt; or custom cubic-bezier values. Here's an example:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/CindyCandyCode/embed/WNqwjQP?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In this example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;@keyframes bounce&lt;/code&gt; rule defines the bounce effect by moving the element up and down.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;.bounce&lt;/code&gt; class applies the &lt;code&gt;bounce&lt;/code&gt; animation, which repeats every 2 seconds indefinitely with an &lt;code&gt;ease&lt;/code&gt; timing function.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I hope this article was helpful, see you on the next one!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>animation</category>
    </item>
    <item>
      <title>The Power of position: 'absolute' and Its Downsides</title>
      <dc:creator>Cindy Kandie</dc:creator>
      <pubDate>Fri, 12 Jul 2024 06:13:56 +0000</pubDate>
      <link>https://dev.to/cindykandie/the-power-of-position-absolute-and-its-downsides-1mih</link>
      <guid>https://dev.to/cindykandie/the-power-of-position-absolute-and-its-downsides-1mih</guid>
      <description>&lt;p&gt;In CSS, position: absolute allows precise control over the placement of elements, making it invaluable for creating overlays, tooltips, and more. However, it also comes with certain drawbacks. Let's explore its uses and potential pitfalls.&lt;/p&gt;

&lt;p&gt;How to Use position: absolute&lt;/p&gt;

&lt;p&gt;When an element is positioned absolutely, it is removed from the normal document flow and positioned relative to its nearest positioned ancestor (an ancestor with position set to relative, absolute, fixed, or sticky). If no such ancestor exists, it will be positioned relative to the initial containing block, typically the html element.&lt;/p&gt;

&lt;p&gt;Example: Simple Absolute Positioning&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I'm absolutely positioned!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;.container {&lt;br&gt;
    position: relative;&lt;br&gt;
    width: 300px;&lt;br&gt;
    height: 200px;&lt;br&gt;
    background-color: lightgray;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.absolute-box {&lt;br&gt;
    position: absolute;&lt;br&gt;
    top: 20px;&lt;br&gt;
    left: 20px;&lt;br&gt;
    width: 100px;&lt;br&gt;
    height: 100px;&lt;br&gt;
    background-color: coral;&lt;br&gt;
}&lt;/p&gt;

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

&lt;p&gt;In this example, the .absolute-box is positioned 20px from the top and 20px from the left of the .container.&lt;/p&gt;

&lt;p&gt;Benefits of position: absolute&lt;/p&gt;

&lt;p&gt;Precise Control: Place elements exactly where you want within a container.&lt;/p&gt;

&lt;p&gt;Layering Elements: Use z-index to control the stacking order.&lt;/p&gt;

&lt;p&gt;Overlay Effects: Create overlays or floating elements easily.&lt;/p&gt;

&lt;p&gt;Example: Creating an Overlay&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="image.jpg" alt="Sample Image"&amp;gt;
Overlay Text
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;.overlay-container {&lt;br&gt;
    position: relative;&lt;br&gt;
    width: 300px;&lt;br&gt;
    height: 200px;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.image {&lt;br&gt;
    width: 100%;&lt;br&gt;
    height: auto;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.overlay {&lt;br&gt;
    position: absolute;&lt;br&gt;
    top: 0;&lt;br&gt;
    left: 0;&lt;br&gt;
    width: 100%;&lt;br&gt;
    height: 100%;&lt;br&gt;
    background: rgba(0, 0, 0, 0.5);&lt;br&gt;
    color: white;&lt;br&gt;
    display: flex;&lt;br&gt;
    align-items: center;&lt;br&gt;
    justify-content: center;&lt;br&gt;
    font-size: 24px;&lt;br&gt;
}&lt;/p&gt;

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

&lt;p&gt;Downsides of position: absolute&lt;/p&gt;

&lt;p&gt;Removed from Document Flow: Surrounding elements won’t adjust to accommodate the absolute element, leading to potential overlap or gaps.&lt;/p&gt;

&lt;p&gt;Complex Responsive Design: Elements may not scale or reposition as expected when the viewport size changes.&lt;/p&gt;

&lt;p&gt;Parent Dimensions Dependency: An absolute element’s position depends on its nearest positioned ancestor.&lt;/p&gt;

&lt;p&gt;Attributes Gained and Lost with position: absolute&lt;/p&gt;

&lt;p&gt;When you assign position: absolute to an element, it gains certain attributes and behaviours while losing others. Understanding these changes is crucial for effectively using absolute positioning in your CSS layouts.&lt;/p&gt;

&lt;p&gt;Attributes Gained with position: absolute&lt;/p&gt;

&lt;p&gt;Top, Right, Bottom, Left: These properties become active and can be used to precisely position the element within its containing parent block. They define the offset of the element relative to its nearest positioned ancestor.&lt;/p&gt;

&lt;p&gt;.absolute-element {&lt;br&gt;
    position: absolute;&lt;br&gt;
    top: 10px;&lt;br&gt;
    right: 20px;&lt;br&gt;
    bottom: 30px;&lt;br&gt;
    left: 40px;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Z-Index: The z-index property determines the stack order of the element along the x axis. Higher values will bring the element to the front/top, allowing you to control layering.&lt;/p&gt;

&lt;p&gt;.absolute-element {&lt;br&gt;
    position: absolute;&lt;br&gt;
    z-index: 10;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Margin and Padding: Margins and paddings can still be used to create space around and within the absolutely positioned element, although their effect is within the context of the element's new position.&lt;/p&gt;

&lt;p&gt;Transform: You can apply CSS transforms (e.g., rotate, scale, translate) to absolutely positioned elements, allowing for dynamic visual effects.&lt;/p&gt;

&lt;p&gt;.absolute-element {&lt;br&gt;
    position: absolute;&lt;br&gt;
    transform: translateX(50%);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Attributes Lost with position: absolute&lt;/p&gt;

&lt;p&gt;Flow Positioning: The element is removed from the normal document flow. This means that it will no longer affect the position of other elements, and other elements will not affect its position. This can lead to overlapping or gaps if not managed carefully.&lt;/p&gt;

&lt;p&gt;Flex and Grid Container Context: While an absolutely positioned element can be a child of a flex or grid container, it will not participate in the layout of these containers. It will be positioned independently of the flex or grid system.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Flex Item #1
Absolute Item
Flex Item #2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;In this example, .absolute-element will not behave like a flex item.&lt;/p&gt;

&lt;p&gt;Parent Dimensions Dependency: When an element is positioned absolutely, it no longer contributes to the height and width of its parent container. This can cause parent containers with no other content to collapse if they do not have a defined height or width.&lt;/p&gt;

&lt;p&gt;Automatic Width and Height: By default, an absolutely positioned element does not stretch to fill its container as a relatively or statically positioned element might. You need to explicitly set its width and height if required.&lt;/p&gt;

&lt;p&gt;.absolute-element {&lt;br&gt;
    position: absolute;&lt;br&gt;
    width: 100%;&lt;br&gt;
    height: 100%;&lt;br&gt;
}&lt;/p&gt;

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

&lt;p&gt;Example Demonstrating Attributes Gained and Lost&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I am absolutely positioned
I am normal content
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;.relative-container {&lt;br&gt;
    position: relative;&lt;br&gt;
    width: 400px;&lt;br&gt;
    height: 300px;&lt;br&gt;
    background-color: lightgray;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.absolute-box {&lt;br&gt;
    position: absolute;&lt;br&gt;
    top: 20px;&lt;br&gt;
    left: 20px;&lt;br&gt;
    width: 150px;&lt;br&gt;
    height: 100px;&lt;br&gt;
    background-color: coral;&lt;br&gt;
    z-index: 10;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;.content-box {&lt;br&gt;
    width: 100%;&lt;br&gt;
    height: 200px;&lt;br&gt;
    background-color: lightblue;&lt;br&gt;
}&lt;/p&gt;

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

&lt;p&gt;In this example:&lt;/p&gt;

&lt;p&gt;The .absolute-box uses top and left to position itself within the .relative-container.&lt;/p&gt;

&lt;p&gt;The z-index property ensures it appears above other elements if there is overlap.&lt;/p&gt;

&lt;p&gt;The .content-box remains within the normal document flow, and its dimensions do not affect or get affected by the .absolute-box.&lt;/p&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Assigning position: absolute to an element provides powerful control over its placement and layering but also removes it from the document flow and the context of its parent container's layout system. This dual nature requires careful management to avoid unintended layout issues while leveraging the precision and flexibility it offers.&lt;/p&gt;

&lt;p&gt;Happy coding!😉&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>tailwindcss</category>
      <category>positionabsolute</category>
    </item>
    <item>
      <title>Why and How to Use Box-Sizing: 'Border-Box' in Your CSS Layouts</title>
      <dc:creator>Cindy Kandie</dc:creator>
      <pubDate>Fri, 05 Jul 2024 02:28:59 +0000</pubDate>
      <link>https://dev.to/cindykandie/why-and-how-to-use-box-sizing-border-box-in-your-css-layouts-30ei</link>
      <guid>https://dev.to/cindykandie/why-and-how-to-use-box-sizing-border-box-in-your-css-layouts-30ei</guid>
      <description>&lt;p&gt;When working with CSS, one of the most crucial yet often misunderstood properties is &lt;code&gt;box-sizing&lt;/code&gt;. This property plays a significant role in how elements are sized and can make the difference between a layout that behaves as expected and one that doesn't. In this article, we'll dive deep into the &lt;code&gt;box-sizing&lt;/code&gt; attribute, understand its variations, and explore why it is essential for creating consistent and predictable layouts.&lt;/p&gt;

&lt;h4&gt;
  
  
  What is &lt;code&gt;box-sizing&lt;/code&gt;?
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;box-sizing&lt;/code&gt; property allows us to control how the width and height of an element are calculated. By default, CSS uses the &lt;code&gt;content-box&lt;/code&gt; value for &lt;code&gt;box-sizing&lt;/code&gt;, which means the width and height you set for an element only include the content area, excluding padding and border. However, this default behaviour can often lead to unexpected results, especially when adding padding and borders.&lt;/p&gt;

&lt;h4&gt;
  
  
  Variations of &lt;code&gt;box-sizing&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;There are two primary values for the &lt;code&gt;box-sizing&lt;/code&gt; property:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;content-box&lt;/code&gt; (default): The width and height properties include only the content. Padding and border are added outside of the content area, increasing the total size of the element unexpectedly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;border-box&lt;/code&gt;: The width and height properties include the content, padding, and border. This means the total size of the element is constrained to the specified width and height, regardless of padding or border.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's explore how these variations work with some practical examples.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example: &lt;code&gt;content-box&lt;/code&gt; vs. &lt;code&gt;border-box&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Consider the following HTML and CSS:&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;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"content-box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Content Box&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;"border-box"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Border Box&lt;span class="nt"&gt;&amp;lt;/div&amp;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 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;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&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;20px&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;10px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#333&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.content-box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;content-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="err"&gt;//the&lt;/span&gt; &lt;span class="err"&gt;default&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;lightblue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.border-box&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&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;lightcoral&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;
  
  
  Results
&lt;/h3&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%2Fr21dsz6uiehnj2bf949p.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%2Fr21dsz6uiehnj2bf949p.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When using &lt;code&gt;content-box&lt;/code&gt;, the actual rendered size of the &lt;code&gt;.content-box&lt;/code&gt; element is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Width: 200px (content) + 40px (padding) + 20px (border) = 260px&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Height: 100px (content) + 40px (padding) + 20px (border) = 160px&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In contrast, when using &lt;code&gt;border-box&lt;/code&gt;, the &lt;code&gt;.border-box&lt;/code&gt; element's total size remains exactly 200px by 100px because the padding and border are included in the specified dimensions.&lt;/p&gt;
&lt;h4&gt;
  
  
  Why is &lt;code&gt;box-sizing&lt;/code&gt; Important?
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Predictable Layouts&lt;/strong&gt;: By using &lt;code&gt;box-sizing: border-box&lt;/code&gt;, you ensure that the dimensions you set are the dimensions you get. This predictability is crucial when creating complex layouts, especially in responsive design where elements must fit perfectly within their containers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simplified Calculations&lt;/strong&gt;: With &lt;code&gt;border-box&lt;/code&gt;, you don't have to calculate and adjust for padding and border manually, simplifying the process of setting element sizes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency Across Elements&lt;/strong&gt;: Applying &lt;code&gt;box-sizing: border-box&lt;/code&gt; globally ensures a consistent box model throughout your project, reducing the chances of layout inconsistencies and bugs.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  Practical Example: Global &lt;code&gt;box-sizing&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;A common best practice is to apply &lt;code&gt;box-sizing: border-box&lt;/code&gt; to all elements using a universal selector:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="o"&gt;*,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nd"&gt;::before&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nd"&gt;::after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;This rule ensures that all elements, including pseudo-elements, adhere to the &lt;code&gt;border-box&lt;/code&gt; model, providing a solid foundation for your layouts.&lt;/p&gt;

&lt;h4&gt;
  
  
  Maintaining Dimensions with Borders
&lt;/h4&gt;

&lt;p&gt;Consider the following example where we have a simple circle without any &lt;code&gt;box-sizing&lt;/code&gt; applied:&lt;/p&gt;

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

&lt;span class="nx"&gt;htmlCopy&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;pink&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;align&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;justify&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;center&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="nx"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;border&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="o"&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;lt;&lt;/span&gt;&lt;span class="sr"&gt;/style&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;&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%2Fbysn91u0ydq72e94vi5j.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%2Fbysn91u0ydq72e94vi5j.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, no &lt;code&gt;box-sizing&lt;/code&gt; is needed as no additional elements like borders or padding affect its 100px width and height.&lt;/p&gt;

&lt;p&gt;Now, let's say you want to add a border to the circle while still maintaining its dimensions:&lt;/p&gt;

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

&lt;span class="nx"&gt;htmlCopy&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;pink&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;align&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;justify&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;center&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="nx"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;border&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%&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="mi"&gt;30&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt; &lt;span class="nx"&gt;solid&lt;/span&gt; &lt;span class="nx"&gt;purple&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;lt;&lt;/span&gt;&lt;span class="sr"&gt;/style&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;&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%2F0sml163cznjfyb827ei0.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%2F0sml163cznjfyb827ei0.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Simply adding the border increases the width and height by 60px each (30px border on all sides). To maintain the original dimensions, you could reduce the width and height by 60px, but using &lt;code&gt;box-sizing: border-box&lt;/code&gt; allows you to avoid manual calculations:&lt;/p&gt;

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

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;pink&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;align&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;justify&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;center&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="nx"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;border&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%&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="mi"&gt;30&lt;/span&gt;&lt;span class="nx"&gt;px&lt;/span&gt; &lt;span class="nx"&gt;solid&lt;/span&gt; &lt;span class="nx"&gt;purple&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;-&lt;/span&gt;&lt;span class="nx"&gt;sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;border&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//simply add this&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/style&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;

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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Result:&lt;/strong&gt;&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%2Fmbyiyu0m0jlw7a1kwo0m.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%2Fmbyiyu0m0jlw7a1kwo0m.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Adding the &lt;code&gt;box-sizing: border-box&lt;/code&gt; attribute helps you maintain the circle's dimensions while achieving your design goals.&lt;/p&gt;

&lt;h4&gt;
  
  
  Creative Uses of &lt;code&gt;box-sizing&lt;/code&gt;
&lt;/h4&gt;

&lt;p&gt;Beyond maintaining consistent layouts, &lt;code&gt;box-sizing&lt;/code&gt; can be creatively used to achieve specific design effects. For example, when creating a button with equal padding inside, using &lt;code&gt;border-box&lt;/code&gt; ensures that adding borders or increasing padding does not affect the overall size of the button, preserving the design integrity.&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;button&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;10px&lt;/span&gt; &lt;span class="m"&gt;20px&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;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#f0f0f0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&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 button's size remains consistent, regardless of any changes to padding or border, making it easier to maintain uniformity across different buttons.&lt;/p&gt;

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;Understanding and effectively using the &lt;code&gt;box-sizing&lt;/code&gt; property is vital for any CSS developer aiming to create reliable and maintainable layouts. By adopting &lt;code&gt;box-sizing: border-box&lt;/code&gt;, you can simplify your CSS, avoid common pitfalls, and ensure that your designs are consistent across different elements and screen sizes. Embrace the power of &lt;code&gt;box-sizing&lt;/code&gt; to keep your layouts in perfect order and elevate your CSS skills to the next level.  &lt;/p&gt;

&lt;p&gt;See you on the next one!&lt;/p&gt;

</description>
      <category>css</category>
      <category>tailwindcss</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
