CSS in 15 mins: tutorial

What is CSS ?

  • CSS (Cascading Style Sheets) is a stylesheet language used for describing the look and formatting of a document or web page written in HTML.
  • CSS allows you to apply styles to HTML elements, such as color, font, layout, and more.
  • CSS apply styles to HTML elements using selectors and declarations

Example HTML code: styled “hello World”text to red color in paragraph tag

Output:

Consolidated CSS tag list:

CSS TagDescriptionSyntaxExample
font-sizeSets the font size of textfont-size: 20px;p { font-size: 20px; }
colorSets the text colorcolor: red;p { color: red; }
background-colorSets the background color of an elementbackground-color: yellow;body { background-color: yellow; }
paddingSets the space within an elementpadding: 10px 20px;p { padding: 10px 20px; }
marginSets the space outside an elementmargin: 10px 20px;p { margin: 10px 20px; }
borderSets a border around an elementborder: 1px solid black;p { border: 1px solid black; }
widthSets the width of an elementwidth: 500px;div { width: 500px; }
heightSets the height of an elementheight: 300px;div { height: 300px; }
text-alignAligns the text within an elementtext-align: center;`p { text-align: center;

Additional CSS tags:

CSS TagDescriptionSyntaxExample
font-familySets the font-family of textfont-family: Arial;p { font-family: Arial; }
font-weightSets the font weightfont-weight: bold;p { font-weight: bold; }
text-decorationAdds a text decorationtext-decoration: underline;a { text-decoration: underline; }
displaySpecifies the type of display for an elementdisplay: inline;span { display: inline; }
floatSpecifies the position of an elementfloat: left;img { float: left; }
clearSpecifies which sides of an element other floating elements are not allowedclear: both;.clearfix::after { clear: both; }
positionSpecifies the type of positioning method used for an elementposition: absolute;
CSS TagDescriptionSyntaxExample
leftSets the left position of an absolutely positioned elementleft: 10px;div { position: absolute; left: 10px; }
topSets the top position of an absolutely positioned elementtop: 20px;div { position: absolute; top: 20px; }
rightSets the right position of an absolutely positioned elementright: 30px;div { position: absolute; right: 30px; }
bottomSets the bottom position of an absolutely positioned elementbottom: 40px;div { position: absolute; bottom: 40px; }
overflowSpecifies what to do with content that overflows an element’s boxoverflow: auto;div { overflow: auto; }
visibilitySpecifies whether or not an element is visiblevisibility: hidden;div { visibility: hidden; }
z-indexSpecifies the stack order of an elementz-index: 1;div { position: absolute; z-index: 1; }
list-style-typeSpecifies the type of list-item markerlist-style-type: square;ul { list-style-type: square; }
max-widthSets the maximum width of an elementmax-width: 500px;img { max-width: 500px; }
min-heightSets the minimum height of an elementmin-height: 300px;div { min-height: 300px; }
CSS TagDescriptionSyntaxExample
background-colorSpecifies the background color of an elementbackground-color: yellow;body { background-color: yellow; }
background-imageSpecifies a background image for an elementbackground-image: url(bg.jpg);body { background-image: url(bg.jpg); }
background-repeatSpecifies if/how a background image should be repeatedbackground-repeat: repeat-x;body { background-image: url(bg.jpg); background-repeat: repeat-x; }
background-attachmentSpecifies if/how a background image should scroll with the contentbackground-attachment: fixed;body { background-image: url(bg.jpg); background-attachment: fixed; }
background-positionSpecifies the position of a background imagebackground-position: right top;body { background-image: url(bg.jpg); background-position: right top; }
borderA shorthand property for setting all border properties in one lineborder: 1px solid black;p { border: 1px solid black; }
border-colorSpecifies the color of a borderborder-color: blue;p { border: 1px solid blue; }
border-styleSpecifies the style of a borderborder-style: dotted;p { border: 1px dotted black; }
border-widthSpecifies the width of a borderborder-width: 2px;p { border: 2px solid black; }
border-radiusSpecifies the rounding of the corners of an element’s borderborder-radius: 25px;p { border: 1px solid black; border-radius: 25px; }

2D and 3D transformations
CSS TagDescriptionSyntaxExample
transformApplies a 2D or 3D transformation to an elementtransform: rotate(30deg);div { transform: rotate(30deg); }
transform-originSpecifies the origin of a 2D or 3D transformationtransform-origin: right top;div { transform: rotate(30deg); transform-origin: right top; }
perspectiveSpecifies the distance from the z=0 plane that the 3D elements are displayed fromperspective: 500px;body { perspective: 500px; }
perspective-originSpecifies the origin for the perspective propertyperspective-origin: right top;body { perspective: 500px; perspective-origin: right top; }

Animation
CSS TagDescriptionSyntaxExample
animationA shorthand property for setting all animation properties in one lineanimation: spin 5s infinite linear;div { animation: spin 5s infinite linear; }
animation-nameSpecifies the name of an animationanimation-name: spin;div { animation-name: spin; }
animation-durationSpecifies the duration of an animationanimation-duration: 5s;div { animation-name: spin; animation-duration: 5s; }
animation-timing-functionSpecifies the speed curve of an animationanimation-timing-function: linear;div { animation-name: spin; animation-duration: 5s; animation-timing-function: linear; }
animation-delaySpecifies the delay before an animation startsanimation-delay: 2s;div { animation-name: spin; animation-duration: 5s; animation-timing-function: linear; animation-delay: 2s; }
animation-iteration-countSpecifies the number of times an animation should runanimation-iteration-count: infinite;div { animation-name: spin; animation-duration: 5s; animation-timing-function: linear; animation-iteration-count: infinite; }
animation-directionSpecifies the direction of an animationanimation-direction: reverse;div { animation-name: spin; animation-duration: 5s; animation-timing-function: linear; animation-direction: reverse; }
animation-fill-modeSpecifies what styles will apply before/after an animationanimation-fill-mode: forwards;div { animation-name: spin; animation-duration: 5s; animation-timing-function: linear; animation-fill-mode: forwards; }
Responsive Design
CSS TagDescriptionSyntaxExample
@mediaA media query, used to apply CSS styles based on device characteristics such as screen size@media (max-width: 600px) { … }@media (max-width: 600px) { body { font-size: 12px; } }
min-widthSpecifies the minimum width of an elementmin-width: 600px;@media (min-width: 600px) { body { font-size: 16px; } }
max-widthSpecifies the maximum width of an elementmax-width: 600px;@media (max-width: 600px) { body { font-size: 12px; } }
min-heightSpecifies the minimum height of an elementmin-height: 400px;@media (min-height: 400px) { body { background-color: lightgray; } }
max-heightSpecifies the maximum height of an elementmax-height: 400px;@media (max-height: 400px) { body { background-color: lightgray; } }
displaySpecifies the display behavior of an elementdisplay: none;@media (max-width: 600px) { nav { display: none; } }
widthSpecifies the width of an elementwidth: 100%;@media (max-width: 600px) { body { width: 100%; } }
heightSpecifies the height of an elementheight: 100%;@media (max-height: 400px) { body { height: 100%; } }

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top