+++ date = 2019-01-07 title = "Useful CSS Snippets" description = "Explore some useful CSS snippets." +++ # Introduction to CSS [CSS](https://en.wikipedia.org/wiki/CSS), the language used to markup HTML code and make it "pretty", is one of the most effective ways to increase the attractiveness of a website. It can also lead to increased user engagement, retention, and satisfaction. In fact, there are whole career fields are dedicated to the improvement of user experiences, known as UI design and UX design. Some web developers are used to the common CSS properties, such as element sizing, fonts, colors, etc., but are not as well versed in less-used properties and values such as `flexbox`, `clip-path`, and `transform`. This article will provide some insight into the less-used and unique CSS properties. # CSS Variables The first topic today is CSS variables. Variables are not often used by smaller developers. CSS variables allow you to give your website a well-defined structure, where you can easily reuse CSS properties throughout the project. You can use variables to define things, such as color palettes. Then, you can use these colors for backgrounds anywhere else in the HTML. This could be extended, where extra variables could be defined for `primary-text`, `quoted-text`, etc. Variables can also be used to define spacing (e.g. `32px` or `2rem`), which can then be applied to margins, padding, font sizes, and more. For example, here are some variables defined at the root of the website, which allows for any subsequent CSS rules to use those variables: ```css :root { --primary-color: black; --secondary-color: white; } body { background-color: var(--primary-color); color: var(--secondary-color); } ``` # CSS Box Shadows Box shadows were once my mortal enemy. No matter how hard I tried, I just couldn't get them to work how I wanted. Because of this, my favorite discovery has been CSSMatic's [box shadow generator](https://www.cssmatic.com/box-shadow). It provides an excellent tool to generate box shadows using their simple sliders. Surprisingly, this is the reason I learned how box shadows work! You can use the sliders and watch how the CSS code changes in the image that is displayed. Through this, you should understand that the basic structure for box shadows is: ```css box-shadow: inset horizontal vertical blur spread color; ``` Now, let's look at some basic examples! You can copy and paste the following code into a site like CodePen or your own HTML files. Feel free to play around with the code, experiment, and learn. ****Box Shadow #1**** ```html