How to Write CSS Code
CSS code consists of selectors, properties, and values working together to style HTML elements.
- How to structure CSS rules
- Understanding selectors, properties, and values
- Key CSS terminology
Parts of CSS Code
CSS code uses selectors to choose elements, properties to define what to change, and values to set the specific style.
credit: bikegremlin.com for this image
Selectors Target HTML Elements
Selectors are used to target HTML elements that you want to style. There are different types of selectors, including element selectors, class selectors, and ID selectors.
Properties Define Styles
Properties are used to define the styles that you want to apply to the selected elements. There are many different properties available in CSS, including color, font-size, margin, padding, and more.
Values Set Property Settings
Values are used to specify the settings for the properties. For example, if you want to set the color of an element to red, you would use the property "color" and the value "red".
Key CSS Terms to Know
- Selector: The HTML element that you want to style.
- Property: The style that you want to apply to the selected element.
- Value: The setting for the property.
- Declaration: A combination of a property and a value.
- Rule: A combination of a selector and one or more declarations.