Adam Gaffney's HTML and CSS Cheatsheet

Skip Navigation

About this page

This is my Codecademy project for the HTML & CSS Cheatsheet. I have added multiple sections which split up the different aspects of HTML and CSS.


The buttons above can be used to jump between the different sections, and within each of these sections are subsections with buttons. Clicking or tapping on these buttons will bring up a modal that will give you much more information on whatever was clicked on. These modals can be closed by using the X in the top right corner or by just clicking anywhere off the modal. In addition, the "More Information" section has superscripts like this[2] which are also links. Click these to open resources mentioned in the text.


Thank you for visiting, and I hope you can perhaps find this as helpful as I do. I would appreciate anything that you think should be edited or added.

HTML

HTML Concepts

The DOM

The Document Object Model (DOM) is the core of the web experience. It is what allows the page to have structure and allows user and developer alike to interact with the webpage. Thanks to the elements of the web document being objects, we can access and alter the properties of the web page easily using normal Object Oriented Programming (OOP) style methods.


For example document.querySelector() calls the querySelector method of the document itself, allowing us to fetch elements of the DOM in Javascript. This lets us dynamically access and edit elements of the DOM and give more functionality to our webpage.


The DOM is rendered sequentially, meaning that each element is placed top to bottom. This is significant not only for the ordering of elements on the page, but also for loading in scripts. If the script is placed higher in the page than an element it tries to use and isn't loaded asynchronously, then the script will fail as that element has not been loaded into the DOM when the script runs.

More Information

MDN Web Docs about the DOM[1]

Tags

An HTML tag is a specific keyword enclosed by arrow brackets <> used to designate a specific element type that should be rendered at that location in the DOM. There are many different types of tags which will be detailed in the next section, however some examples include:

  • <div>
  • <article>
  • <script>

Tags let the browser and screenreaders know what to expect and render from any particular part of the page. Using our above examples, <div> is a generic section element that can contain any other tags.
Likewise, <article> is a more specific section element using a method called Semantic HTML, which specifies that the content within this section is self-contained and unrelated to anything else on the page.
Finally for our examples we have <script>. This is different in that it's more of a utility tag. This tells the browser that whatever is contained in the href attribute is a script to give the page functionality. More details for all of the above tags are available in the tags section of this page.

More Information

MDN Web Docs about HTML elements[1]

Searchable list of HTML tags[2]

Attributes

Attributes are a way of providing additional information and functionality to HTML elements. There are many standard attributes that can be used, and in many cases custom attributes can be used also which will be detailed later.[2] Attributes can essentially be used as a way to store data on a tag, which can make it easier to manipulate and access specific tags. Some examples of attributes include:

  • class
  • title
  • disabled

Attributes can be accessed both by CSS files and by Javascript files to enhance the functionality of any website. Lets explore our examples to detail this.

One of the most common attributes is class. It is very common to give a tag one or more classes to allow for styling in CSS and even accessing in Javascript, which will be detailed more later.

The next two are more functional tags. For title, this one is used to add tooltips to elements. The browsers detect that a title is present on an element, and will show that tooltip on hover, hover on this text here for an example.

Finally, the disabled attribute will tell the browser that an element is not to be used or accessible whilst the page is loaded. This can be useful for ensuring form elements can only be accessed if certain conditions are met, and is a much simpler built in solution than creating something manually to prevent input in Javascript.

More Information

W3Schools article on HTML attributes[1]

Comment about how to use custom attributes[2]

Semantics
This is card 2

More Information

MDN Web Docs about the DOM[1]

HTML Tags

The DOM

The Document Object Model (DOM) is the core of the web experience. It is what allows the page to have structure and allows user and developer alike to interact with the webpage. Thanks to the elements of the web document being objects, we can access and alter the properties of the web page easily using normal Object Oriented Programming (OOP) style methods.


For example document.querySelector() calls the querySelector method of the document itself, allowing us to fetch elements of the DOM in Javascript. This lets us dynamically access and edit elements of the DOM and give more functionality to our webpage.

More Information

MDN Web Docs about the DOM[1]

Headings

The specificity of a css property is determined by the selectors used, and determines which properties eventually get applied to an element. Some examples selectors include:

  1. #id ul - Specificity (2, 0, 0)
  2. .class.other-class - Specificity (0, 2, 0)
  3. input:after - Specificity (0, 0, 2)

In the above cases, 1 has the highest specificity as it is selecting for an ID. The next highest is 2 as this uses class selectors, followed by 3 with the lowest specificity as this selects only using html elements.

More Information

MDN Web Docs about the DOM[1]

Selectors
This is card 2

More Information

MDN Web Docs about the DOM[1]

CSS

CSS Concepts

Specificity

The specificity of a css property is determined by the selectors used, and determines which properties eventually get applied to an element. Some examples selectors include:

  1. #id ul - Specificity (2, 0, 0)
  2. .class.other-class - Specificity (0, 2, 0)
  3. input:after - Specificity (0, 0, 2)

In the above cases, 1 has the highest specificity as it is selecting for an ID. The next highest is 2 as this uses class selectors, followed by 3 with the lowest specificity as this selects only using html elements.

More Information

MDN Web Docs about the DOM[1]

Selectors
This is card 2

More Information

MDN Web Docs about the DOM[1]

CSS Properties

Display
This is a description

More Information

MDN Web Docs about the DOM[1]

Margin
This is card 4

More Information

MDN Web Docs about the DOM[1]

Padding
This is card 2

More Information

MDN Web Docs about the DOM[1]

Position
This is card 3

More Information

MDN Web Docs about the DOM[1]