Learn CSS - Syntax and Selectors Cheatsheet - Codecademy
Learn CSS - Syntax and Selectors Cheatsheet - Codecademy
The <link> element is used to link HTML documents <!-- How to link an external stylesheet
to external resources like CSS files. It commonly uses:
with href, rel, and type attributes -->
href attribute to specify the URL to the external
resource <link
rel attribute to specify the relationship of the href="./path/to/stylesheet/style.css"
linked document to the current document rel="stylesheet" type="text/css">
type attribute to define the type of content
being linked
Purpose of CSS
https://www.codecademy.com/learn/learn-css/modules/syntax-and-selectors/cheatsheet 1/5
15/11/2023 18:30 Learn CSS: Syntax and Selectors Cheatsheet | Codecademy
Inline Styles
CSS styles can be directly added to HTML elements by <h2 style="text-align: center;">Centered
using the style attribute in the element’s opening tag.
text</h2>
Each style declaration is ended with a semicolon. Styles
added in this manner are known as inline styles.
<p style="color: blue; font-size:
18px;">Blue, 18-point text</p>
CSS classes can be reusable and applied to many /* Selects all elements with
elements. Class selectors are denoted with a period .
class="column" */
followed by the class name. CSS ID selectors should be
unique and used to style only a single element. ID .column {
selectors are denoted with a hash sign # followed by }
the id name.
https://www.codecademy.com/learn/learn-css/modules/syntax-and-selectors/cheatsheet 2/5
15/11/2023 18:30 Learn CSS: Syntax and Selectors Cheatsheet | Codecademy
Selector Chaining
Chaining Selectors
CSS selectors can be chained so that rule sets apply /* Select h3 elements with the section-
only to elements that match all criteria. For instance, to
heading class */
select <h3> elements that also have the section-
heading class, the selector h3.section-heading can be h3.section-heading {
used. color: blue;
}
CSS type selectors are used to match all elements of a /* Selects all <p> tags */
given type or tag name. Unlike for HTML syntax, we do
p {
not include the angle brackets when using type
selectors for tag names. When using type selectors, }
elements are matched regardless of their nesting level
in the HTML.
https://www.codecademy.com/learn/learn-css/modules/syntax-and-selectors/cheatsheet 3/5
15/11/2023 18:30 Learn CSS: Syntax and Selectors Cheatsheet | Codecademy
Some HTML attributes can have multiple attribute <div class="value1 value2 value3"></div>
values. Multiple attribute values are separated by a
space between each attribute.
Selector Specificity
CSS ID selectors
https://www.codecademy.com/learn/learn-css/modules/syntax-and-selectors/cheatsheet 4/5
15/11/2023 18:30 Learn CSS: Syntax and Selectors Cheatsheet | Codecademy
Print Share
https://www.codecademy.com/learn/learn-css/modules/syntax-and-selectors/cheatsheet 5/5