CLASS's vs. ID's - Day 9

TIL (Today I Learned)

Some reddit terminology 101 for ya. Today’s article will be short and sweet since it is a concept better learned through practice than preaching.

CLASS’s

  • Are used for mostly styling purposes
  • Can be used multiple times
  • Can be used on any element

CLASS Example

index.html

<h1 class="title"> Damn Good Brew</h1>

styles.css

.title {
	font-size: 50px;
	font-weight: bold;
}

ID’s

  • Are used mostly for Javascript purposes
  • Can only be used once
  • Can also be used on any element

ID Example

index.html

<h1 id="title"> Damn Good Brew</h1>

index.js

document.getElementById("title");

Conclusion

While both CLASS’s & ID’s can be used for styling AND javascript selectors, it’s best practice to keep the two seperate. To make it easier to read and add functionality as your code becomes more and more complex.

Check out the video below for a more in-depth overview for the Zero to Startup in 30 Days Challenge.

CLASS's vs. ID's

Coming Tomorrow -----> What The Flex? Intro to Flexbox.

Want To Learn How To Turn Your Ideas Into Code?


Written by Tim Moreton who lives and works
in Philadelphia building useful things.