{"id":64,"date":"2026-04-06T17:47:00","date_gmt":"2026-04-06T17:47:00","guid":{"rendered":"https:\/\/gigz.pk\/css\/?post_type=lesson&#038;p=64"},"modified":"2026-04-18T09:24:58","modified_gmt":"2026-04-18T09:24:58","slug":"basic-selectors-in-css","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/css\/lesson\/basic-selectors-in-css\/","title":{"rendered":"Basic Selectors in CSS"},"content":{"rendered":"\n<p>CSS selectors are used to target HTML elements so you can apply styles to them. The most common basic selectors are Element, Class, and ID selectors. Understanding these is the first step in learning CSS.<\/p>\n\n\n\n<p>Element Selector<\/p>\n\n\n\n<p>The element selector targets HTML elements by their tag name. It applies the same style to all elements of that type.<\/p>\n\n\n\n<p>Example explanation<br>If you use the p selector, it will style all paragraph elements on the page.<\/p>\n\n\n\n<p>Example code<br>p<br>color blue<br>font size 16px<\/p>\n\n\n\n<p>This means every paragraph will have blue text and a font size of 16 pixels.<\/p>\n\n\n\n<p>Class Selector<\/p>\n\n\n\n<p>The class selector is used to style one or more elements with the same class name. It is more flexible than the element selector because it can be reused multiple times.<\/p>\n\n\n\n<p>To use a class selector, you add a class attribute in HTML and then target it in CSS using a dot before the class name.<\/p>\n\n\n\n<p>Example explanation<br>If you create a class called box, you can apply the same style to different elements.<\/p>\n\n\n\n<p>Example code<br>dot box<br>background color lightgray<br>padding 10px<\/p>\n\n\n\n<p>In HTML, you can use it like this<br>div class box<br>This is a styled box<br>div<\/p>\n\n\n\n<p>You can use the same class on multiple elements across your webpage.<\/p>\n\n\n\n<p>ID Selector<\/p>\n\n\n\n<p>The ID selector is used to style a single unique element. Each ID should only be used once on a page.<\/p>\n\n\n\n<p>To use an ID selector, you add an id attribute in HTML and target it in CSS using a hash symbol before the ID name.<\/p>\n\n\n\n<p>Example explanation<br>If you create an ID called header, it will style only that specific element.<\/p>\n\n\n\n<p>Example code<br>hash header<br>color red<br>font size 24px<\/p>\n\n\n\n<p>In HTML, it looks like this<br>div id header<br>This is the header section<br>div<\/p>\n\n\n\n<p>Key Differences<\/p>\n\n\n\n<p>Element selector targets all elements of a specific type<br>Class selector can be used multiple times and is reusable<br>ID selector is unique and used for one specific element<\/p>\n\n\n\n<p>Conclusion<\/p>\n\n\n\n<p>Basic selectors are essential for styling web pages. Element selectors are simple, class selectors are flexible, and ID selectors are specific. Mastering these will help you build well-structured and styled websites.<\/p>\n\n\n\n<p>If you want, I can create practice exercises or a full lesson plan for your training website.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/css\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">CSS Fundamentals (Beginner) > Selectors &#038; Properties > Basic Selectors (Element, Class, ID)<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1776504267656\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1776504267333\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":0,"template":"","class_list":["post-64","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Basic Selectors in CSS - CSS learning mastery<\/title>\n<meta name=\"description\" content=\"Learn CSS basic selectors element class and id with simple examples. Improve your web design skills with easy beginner guide\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/css\/lesson\/basic-selectors-in-css\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Basic Selectors in CSS - CSS learning mastery\" \/>\n<meta property=\"og:description\" content=\"Learn CSS basic selectors element class and id with simple examples. Improve your web design skills with easy beginner guide\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/css\/lesson\/basic-selectors-in-css\/\" \/>\n<meta property=\"og:site_name\" content=\"CSS learning mastery\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-18T09:24:58+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/basic-selectors-in-css\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/basic-selectors-in-css\\\/\",\"name\":\"Basic Selectors in CSS - CSS learning mastery\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/#website\"},\"datePublished\":\"2026-04-06T17:47:00+00:00\",\"dateModified\":\"2026-04-18T09:24:58+00:00\",\"description\":\"Learn CSS basic selectors element class and id with simple examples. Improve your web design skills with easy beginner guide\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/basic-selectors-in-css\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/basic-selectors-in-css\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/basic-selectors-in-css\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/css\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"CSS Fundamentals (Beginner) > Selectors & Properties > Basic Selectors (Element, Class, ID)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/css\\\/\",\"name\":\"CSS learning mastery\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/css\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Basic Selectors in CSS - CSS learning mastery","description":"Learn CSS basic selectors element class and id with simple examples. Improve your web design skills with easy beginner guide","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/css\/lesson\/basic-selectors-in-css\/","og_locale":"en_US","og_type":"article","og_title":"Basic Selectors in CSS - CSS learning mastery","og_description":"Learn CSS basic selectors element class and id with simple examples. Improve your web design skills with easy beginner guide","og_url":"https:\/\/gigz.pk\/css\/lesson\/basic-selectors-in-css\/","og_site_name":"CSS learning mastery","article_modified_time":"2026-04-18T09:24:58+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/css\/lesson\/basic-selectors-in-css\/","url":"https:\/\/gigz.pk\/css\/lesson\/basic-selectors-in-css\/","name":"Basic Selectors in CSS - CSS learning mastery","isPartOf":{"@id":"https:\/\/gigz.pk\/css\/#website"},"datePublished":"2026-04-06T17:47:00+00:00","dateModified":"2026-04-18T09:24:58+00:00","description":"Learn CSS basic selectors element class and id with simple examples. Improve your web design skills with easy beginner guide","breadcrumb":{"@id":"https:\/\/gigz.pk\/css\/lesson\/basic-selectors-in-css\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/css\/lesson\/basic-selectors-in-css\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/css\/lesson\/basic-selectors-in-css\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/css\/"},{"@type":"ListItem","position":2,"name":"CSS Fundamentals (Beginner) > Selectors & Properties > Basic Selectors (Element, Class, ID)"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/css\/#website","url":"https:\/\/gigz.pk\/css\/","name":"CSS learning mastery","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/css\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/lesson\/64","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/media?parent=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}