🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 83 (from laksa048)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

đź“„
INDEXABLE
âś…
CRAWLED
15 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.5 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css
Last Crawled2026-03-23 07:16:30 (15 days ago)
First Indexed2020-10-13 15:38:14 (5 years ago)
HTTP Status Code200
Meta TitleHow To Create Classes With CSS | DigitalOcean
Meta DescriptionIn this tutorial, you will create a CSS class selector, which will allow you to apply CSS rules only to HTML elements that are assigned the class. CSS class …
Meta Canonicalnull
Boilerpipe Text
Introduction In this tutorial, you will create a CSS class selector, which will allow you to apply CSS rules only to HTML elements that are assigned the class. CSS class selectors are useful when you want to apply different style rules for different instances of the same HTML element. Prerequisites To follow this tutorial, make sure you have set up the necessary files and folders as instructed in a previous tutorial in this series How To Set Up You CSS and HTML Practice Project . How CSS Class Selectors Work A CSS class selector allows you to assign style rules to HTML elements that you designate with that class rather than all instances of a certain element. Unlike HTML elements (such as <p> , <h1> or <img> ), whose names are predetermined, class names are chosen by the developer when they create the class. Class names are always preceded by a . , which can help you distinguish between tag selectors and class selectors in CSS files. A CSS rule for a class selector is written in the same way as a rule for a tag selector, with the exception of the . prepended to the class name: .red-text { color : red ; } To use a class when adding HTML content to your webpage, you must specify it in the opening tag of an HTML element using the class attribute in your HTML document like so: < h1 class = " .red-text " > Content. </ element > Creating a CSS Class Using a Class Selector Let’s begin exploring CSS classes in practice. Erase everything in your styles.css file and add the following code snippet to specify a rule for the class red-text : styles.css .red-text { color : red ; } After adding the code snippet to your styles.css file, save the file. Return to your index.html and erase everything but the first line of code <link rel="stylesheet" href="css/styles.css"> that links to your CSS stylesheet. Then add the following HTML code snippet: index.html < p class = " red-text " > Here is the first sample of paragraph text. </ p > Note that the class name is not prepended here with a . as it is when being used as a selector for a CSS rule. Your entire index.html file should have the following contents: index.html . . . < link rel = " stylesheet " href = " css/styles.css " > <p class="red-text" Here is the first sample of paragraph text. </ p > In this code snippet you have added text using the HTML <p> tag. But you have also specified the red-text class by adding the highlighted class attribute class="red-text" inside the opening HTML tag. Save your index.html file and load it in the browser. (For instructions on loading an HTML file, please visit our tutorial step How To View An Offline HTML File In Your Browser ). You should receive a webpage with red text: Let’s add an additional CSS class to explore styling different pieces of <p> text content with different classes. Add the following code snippet to your styles.css file (after your CSS rule for “red-text”): styles.css .yellow-background-text { background-color : yellow ; } This CSS rule declares that the class yellow-background-text is assigned the yellow value for the background-color property. Any HTML text element assigned this class will have a yellow background. Note that the use of the word text in the class yellow-background-*text* is for human readability purposes only. You do not need to include the word text in your class names for classes assigned to HTML text. To apply this new CSS class, return to your index.html file and add the following line of code to the bottom: index.html < p class = " yellow-background-text " > Here is the second sample of paragraph text. < p > In this code snippet, you have added some text content with the <p> element and specified the yellow-background-text class. Save the file and reload it in your browser. You should have a webpage with two different sentences, the first one red and the second one with a yellow background: Note that you can add more than one class to an HTML tag. Try adding both classes to a single text element by adding the following line to your index.html file: index.html < p class = " red-text yellow-background-text " > Here is a third sample of text. </ p > Note that the class names are only separated by a space. Save the file and reload it in the browser. You should receive something like this: Your third line of text should now be styled according to the property values set in the red-text class and the yellow-background-text class and have a red font and yellow background. Adding CSS Classes to Images CSS classes can also be applied to other HTML elements, such as images. To explore using CSS classes for images, erase the content in your styles.css file and add the following code snippet: styles.css .black-img { border : 5px dotted black ; border-radius : 10% ; } .yellow-img { border : 25px solid yellow ; border-radius : 50% ; } .red-img { border : 15px double red ; } Here you have created CSS rules for three different classes that can be applied to the HTML <img> tag. Before you move on, let’s briefly study what we’ve declared in each ruleset: The first CSS rule declares that the class black-img should have a black , dotted border five pixels wide and a border-radius sized at 10%, which gives the element rounded corners. The second CSS rule declares that the class yellow-img should have a yellow , solid border 25 pixels wide and a border-radius sized at 50%, which gives the element a circular shape. The third CSS rule declares that the class red-img should have a red , double border 15 pixels wide. You have not set a border-radius, so the border will conform to the element’s shape. Save the styles.css file. Then erase everything from your index.html file (except for the first line of code: <link rel="stylesheet" href="css/styles.css"> ) and add the following code snippet: index.html < img src = " https://css.sammy-codes.com/images/small-profile.jpeg " class = " black-img " > < img src = " https://css.sammy-codes.com/images/small-profile.jpeg " class = " yellow-img " > < img src = " https://css.sammy-codes.com/images/small-profile.jpeg " class = " red-img " > Each of these three lines of HTML code add an image to the HTML document and assign it one of the three classes you just added to the styles.css file. Note that you are sourcing the image from an online location. You can also use your own image by specifying the file path as instructed in our tutorial How To Add Images To Your Webpage With HTML . Save your index.html file and load it in the browser. You should receive something like this: Your webpage should now display three images, each styled with the different specifications of their assigned class. To continue exploring CSS classes, trying creating new classes with different rulesets and applying them to different types of HTML content. Note that properties and values specified in class declaration blocks will only work on elements that they are intended for. For example, a font-color declaration will not change the color of an image border. Likewise, a height declaration will not change the size of the font. Conclusion You have now explored how to create classes, assign them specific property values, and apply them to text and image content. You will return to using classes when you begin building the website in the second half of this tutorial series . In the next tutorial, you will create CSS ID selectors, which work similarly as class selectors with the exception of some unique features. Was this helpful? This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
Markdown
[Now Available: OpenAI GPT-5.4 on the Gradient™ AI Platform](https://www.digitalocean.com/blog/whats-new-on-gradient-ai-platform#week-of-march-2) [Now Available: OpenAI GPT-5.3 Codex on the Gradient™ AI Platform](https://www.digitalocean.com/blog/whats-new-on-gradient-ai-platform#week-of-february-23rd) [Now Available: Claude Sonnet 4.6 on the Gradient™ AI Platform](https://www.digitalocean.com/blog/whats-new-on-gradient-ai-platform#week-of-february-17th) [Heroku is shifting to sustaining engineering. Migrate your workloads to DigitalOcean](https://www.digitalocean.com/blog/migrate-heroku-to-digitalocean) [Now Available: Claude Opus 4.6 on Gradient™ AI Platform](https://www.digitalocean.com/blog/claude-opus-4-6-gradient-ai-platform) [🔥 Run OpenClaw on DigitalOcean App Platform](https://www.digitalocean.com/blog/openclaw-digitalocean-app-platform) [Join us for Deploy in San Francisco, on April 28, 2026. Register now](https://www.digitalocean.com/deploy) - [Blog](https://www.digitalocean.com/blog) - [Docs](https://docs.digitalocean.com/products) - [Careers](https://www.digitalocean.com/careers) - [Get Support](https://www.digitalocean.com/support) - [Contact Sales](https://www.digitalocean.com/company/contact/sales?referrer=tophat) [DigitalOcean](https://www.digitalocean.com/) - Products - Featured Products - [Droplets Scalable virtual machines](https://www.digitalocean.com/products/droplets) - [Kubernetes Scale more effectively](https://www.digitalocean.com/products/kubernetes) - [Gradient™ AI Inference Cloud Build and scale with AI](https://www.digitalocean.com/products/gradient) - [Cloudways Managed cloud hosting](https://www.digitalocean.com/products/cloudways) - [App Platform Get apps to market faster](https://www.digitalocean.com/products/app-platform) - [Managed Databases Fully-managed database hosting](https://www.digitalocean.com/products/managed-databases) [See all products](https://www.digitalocean.com/products) - Solutions - - - [AI and Machine Learning](https://www.digitalocean.com/products/gradient) Develop, train, and deploy AI apps - [GPUs](https://www.digitalocean.com/products/gradient/gpu-droplets) - [Platform](https://www.digitalocean.com/products/gradient/platform) - [1-Click Models](https://www.digitalocean.com/products/gradient/1-click-models) - [HR Knowledge Assistant](https://www.digitalocean.com/solutions/ai-hr-knowledge-assistant) - [Code Copilot](https://www.digitalocean.com/solutions/ai-code-copilot) - [Support Ticket Triage](https://www.digitalocean.com/solutions/ai-support-ticket-triage) - [Recommendation Engine](https://www.digitalocean.com/solutions/ai-recommendation-engine) - [Blockchain](https://www.digitalocean.com/solutions/blockchain) Infrastructure for decentralized apps - [Blogs, Forums and Content Websites](https://www.digitalocean.com/solutions/content-hosting) Lightning-fast, reliable CMS hosting - [Wordpress](https://www.digitalocean.com/solutions/wordpress-hosting) - [Ghost](https://marketplace.digitalocean.com/apps/ghost) - [Mastodon](https://marketplace.digitalocean.com/apps/mastodon) - [Data Analytics](https://www.digitalocean.com/solutions/data-analytics) Real-time data processing at scale - [Data Streaming](https://www.digitalocean.com/solutions/data-streaming-cloud) - [AdTech & Martech](https://www.digitalocean.com/solutions/adtech-martech) - [Kafka](https://www.digitalocean.com/products/managed-databases-kafka?utm_source=top-nav-data-analytics) - - [Developer Tools](https://www.digitalocean.com/solutions/developer-tools) DevOps and CI/CD solutions - [CI/CD](https://www.digitalocean.com/solutions/cicd-pipelines) - [Prototyping](https://www.digitalocean.com/solutions/prototype-hosting) - [Digital Marketing Agencies](https://www.digitalocean.com/solutions/digital-marketing-agencies) Power your clients’ websites and campaigns - [Freelancer](https://www.digitalocean.com/solutions/freelancer-website-hosting) - [IT Consulting](https://www.digitalocean.com/solutions/it-consulting) - [Ecommerce](https://www.digitalocean.com/solutions/ecommerce-hosting) Build beautiful online storefronts - [Dropshipping](https://www.digitalocean.com/solutions/dropshipping-hosting) - [WooCommerce](https://marketplace.digitalocean.com/apps/wordpress-woocommerce) - [Magento](https://marketplace.digitalocean.com/apps/magento-2-open-source) - [Game Development](https://www.digitalocean.com/solutions/gaming-development) Low-latency multiplayer servers - [Minecraft Hosting](https://marketplace.digitalocean.com/apps/minecraft-java-edition-server) - - [IoT](https://www.digitalocean.com/solutions/iot-cloud) Connect to the power of the cloud - [Kafka](https://www.digitalocean.com/products/managed-databases-kafka?utm_source=top-nav-iot) - [ISVs](https://www.digitalocean.com/solutions/isv) Streamlined ISV application development - [Secure Web Hosting](https://www.digitalocean.com/solutions/secure-web-hosting) Powerful protection from DDoS and more - [Private VPN](https://www.digitalocean.com/solutions/vpn) - [Startup Cloud Hosting](https://www.digitalocean.com/solutions/startups) Scalable, cost-effective infrastructure - [Small Business](https://www.digitalocean.com/solutions/small-business-website-hosting) - [Video Streaming](https://www.digitalocean.com/solutions/streaming) High-bandwidth, low-latency delivery - [Kafka](https://www.digitalocean.com/products/managed-databases-kafka?utm_source=top-nav-video-streaming) - - [Web and Mobile Apps](https://www.digitalocean.com/solutions/web-mobile-apps) Simple cross-platform app hosting - [cPanel](https://www.digitalocean.com/solutions/cpanel-hosting) - [Docker](https://www.digitalocean.com/solutions/docker-hosting) - [Next.js](https://www.digitalocean.com/solutions/nextjs-hosting) - [Node.js](https://www.digitalocean.com/solutions/nodejs-hosting) - [Website Hosting](https://www.digitalocean.com/solutions/website-hosting) Fast page loads and reliable site uptime - [VPS Hosting](https://www.digitalocean.com/solutions/vps-hosting) - [Virtual Machines](https://www.digitalocean.com/solutions/virtual-machines) [See all solutions](https://www.digitalocean.com/business) - Developers - Our Community - [Community Home DevOps and development guides](https://www.digitalocean.com/community) - [CSS-Tricks All things web design](https://css-tricks.com/) - [The Wave Content to level up your business.](https://www.digitalocean.com/resources) - Partners - DigitalOcean Partner Programs - [Become a Partner](https://www.digitalocean.com/partners/pod) - [Partner Services Program](https://www.digitalocean.com/partners/services) - [DigitalOcean AI Partner Program](https://www.digitalocean.com/partners/ai-partner-program) - [Marketplace](https://marketplace.digitalocean.com/) - [DigitalOcean Startups](https://www.digitalocean.com/startups) - [Connect with a Partner](https://www.digitalocean.com/partners/directory) - [Pricing](https://www.digitalocean.com/pricing) - Log in - [Community](https://www.digitalocean.com/api/dynamic-content/v1/login?success_redirect=https%3A%2F%2Fwww.digitalocean.com%2Fcommunity%2Ftutorials%2Fhow-to-create-classes-with-css&error_redirect=https%3A%2F%2Fwww.digitalocean.com%2Fauth-error&type=login) - [DigitalOcean](https://cloud.digitalocean.com/login) - Sign up - [Community](https://www.digitalocean.com/api/dynamic-content/v1/login?success_redirect=https%3A%2F%2Fwww.digitalocean.com%2Fcommunity%2Ftutorials%2Fhow-to-create-classes-with-css&error_redirect=https%3A%2F%2Fwww.digitalocean.com%2Fauth-error&type=register) - [DigitalOcean](https://cloud.digitalocean.com/registrations/new) - [Blog](https://www.digitalocean.com/blog) - [Docs](https://docs.digitalocean.com/products) - [Careers](https://www.digitalocean.com/careers) - [Get Support](https://www.digitalocean.com/support) - [Contact Sales](https://www.digitalocean.com/company/contact/sales?referrer=tophat) - Log in - [Community](https://www.digitalocean.com/api/dynamic-content/v1/login?success_redirect=https%3A%2F%2Fwww.digitalocean.com%2Fcommunity%2Ftutorials%2Fhow-to-create-classes-with-css&error_redirect=https%3A%2F%2Fwww.digitalocean.com%2Fauth-error&type=login) - [DigitalOcean](https://cloud.digitalocean.com/login) - Sign up - [Community](https://www.digitalocean.com/api/dynamic-content/v1/login?success_redirect=https%3A%2F%2Fwww.digitalocean.com%2Fcommunity%2Ftutorials%2Fhow-to-create-classes-with-css&error_redirect=https%3A%2F%2Fwww.digitalocean.com%2Fauth-error&type=register) - [DigitalOcean](https://cloud.digitalocean.com/registrations/new) - [Tutorials](https://www.digitalocean.com/community/tutorials) - [Questions](https://www.digitalocean.com/community/questions) - [Product Docs](https://docs.digitalocean.com/) - Search Community ## Report this What is the reason for this report? This undefined is spam This undefined is offensive This undefined is off-topic This undefined is other Submit ## Table of contents 1. [Prerequisites](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#prerequisites) 2. [How CSS Class Selectors Work](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#how-css-class-selectors-work) 3. [Creating a CSS Class Using a Class Selector](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#creating-a-css-class-using-a-class-selector) 4. [Adding CSS Classes to Images](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#adding-css-classes-to-images) 5. [Conclusion](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#conclusion) 1. [Tutorial Series](https://www.digitalocean.com/community/tutorials?type=tutorial_series&subtype=tutorial_series) 2. How To Build a Website With CSS [Tutorial](https://www.digitalocean.com/community/tutorials?subtype=tutorial) # How To Create Classes With CSS Published on October 13, 2020 [CSS](https://www.digitalocean.com/community/tags/css) [Spin Up](https://www.digitalocean.com/community/tags/spin-up) ![Erin Glass](https://www.gravatar.com/avatar/a0f19b54dd93645bbb10a0e06719054c5f77c687d9066b70921e3f0aa644d08d?default=retro&size=256) By [Erin Glass](https://www.digitalocean.com/community/users/eglass) Senior Manager, DevEd ![How To Create Classes With CSS](https://www.digitalocean.com/api/static-content/v1/images?src=https%3A%2F%2Fcommunity-cdn-digitalocean-com.global.ssl.fastly.net%2FxP6vGmY7Cwr29DDyNUcucPgR&width=1920) Table of contents Popular topics ### [Introduction](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#introduction) In this tutorial, you will create a CSS *class* selector, which will allow you to apply CSS rules only to HTML elements that are assigned the class. CSS class selectors are useful when you want to apply different style rules for different instances of the same HTML element. ## [Prerequisites](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#prerequisites) To follow this tutorial, make sure you have set up the necessary files and folders as instructed in a previous tutorial in this series [How To Set Up You CSS and HTML Practice Project](https://www.digitalocean.com/community/tutorials/how-to-set-up-your-css-and-html-practice-project). ## [How CSS Class Selectors Work](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#how-css-class-selectors-work) A CSS class selector allows you to assign style rules to HTML elements that you designate with that class rather than *all* instances of a certain element. Unlike HTML elements (such as `<p>`, `<h1>` or `<img>`), whose names are predetermined, class names are chosen by the developer when they create the class. Class names are always preceded by a `.`, which can help you distinguish between tag selectors and class selectors in CSS files. A CSS rule for a class selector is written in the same way as a rule for a tag selector, with the exception of the `.` prepended to the class name: ``` .red-text { color: red; } ``` Copy To use a class when adding HTML content to your webpage, you must specify it in the opening tag of an HTML element using the class [attribute](https://www.digitalocean.com/community/tutorials/how-to-use-html-attributes) in your HTML document like so: ``` <h1 class=".red-text ">Content.</element> ``` Copy ## [Creating a CSS Class Using a Class Selector](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#creating-a-css-class-using-a-class-selector) Let’s begin exploring CSS classes in practice. Erase everything in your `styles.css` file and add the following code snippet to specify a rule for the class `red-text`: styles.css ``` .red-text { color: red; } ``` Copy After adding the code snippet to your `styles.css` file, save the file. Return to your `index.html` and erase everything but the first line of code `<link rel="stylesheet" href="css/styles.css">` that links to your CSS stylesheet. Then add the following HTML code snippet: index.html ``` <p class="red-text ">Here is the first sample of paragraph text.</p> ``` Copy Note that the class name is not prepended here with a `.` as it is when being used as a selector for a CSS rule. Your entire `index.html` file should have the following contents: index.html ``` . . . <link rel="stylesheet" href="css/styles.css"> <p class="red-text" Here is the first sample of paragraph text.</p> ``` Copy In this code snippet you have added text using the HTML `<p>` tag. But you have also specified the `red-text` class by adding the highlighted class [attribute](https://www.digitalocean.com/community/tutorials/how-to-use-html-attributes) `class="red-text"` *inside* the opening HTML tag. Save your `index.html` file and load it in the browser. (For instructions on loading an HTML file, please visit our tutorial step [How To View An Offline HTML File In Your Browser](https://www.digitalocean.com/community/tutorials/how-to-use-and-understand-html-elements#how-to-view-an-offline-html-file-in-your-browser)). You should receive a webpage with red text: ![Webpage output with red paragraph text](https://assets.digitalocean.com/articles/how-to-build-a-website-with-css/red-text.png) Let’s add an additional CSS class to explore styling different pieces of `<p>` text content with different classes. Add the following code snippet to your `styles.css` file (after your CSS rule for “red-text”): styles.css ``` .yellow-background-text { background-color: yellow; } ``` Copy This CSS rule declares that the class `yellow-background-text` is assigned the `yellow` value for the `background-color` property. Any HTML text element assigned this class will have a yellow background. Note that the use of the word `text`in the class `yellow-background-*text*` is for human readability purposes only. You do not need to include the word `text` in your class names for classes assigned to HTML text. To apply this new CSS class, return to your `index.html` file and add the following line of code to the bottom: index.html ``` <p class="yellow-background-text"> Here is the second sample of paragraph text.<p> ``` Copy In this code snippet, you have added some text content with the `<p>` element and specified the `yellow-background-text` class. Save the file and reload it in your browser. You should have a webpage with two different sentences, the first one red and the second one with a yellow background: ![Webpage with text styled by two classes](https://assets.digitalocean.com/articles/how-to-build-a-website-with-css/two-classes.png) Note that you can add more than one class to an HTML tag. Try adding both classes to a single text element by adding the following line to your `index.html` file: index.html ``` <p class="red-text yellow-background-text">Here is a third sample of text.</p> ``` Copy Note that the class names are only separated by a space. Save the file and reload it in the browser. You should receive something like this: ![IWebpage with text styled by three classes](https://assets.digitalocean.com/articles/how-to-build-a-website-with-css/three-classes.png) Your third line of text should now be styled according to the property values set in the `red-text` class and the `yellow-background-text` class and have a red font and yellow background. ## [Adding CSS Classes to Images](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#adding-css-classes-to-images) CSS classes can also be applied to other HTML elements, such as images. To explore using CSS classes for images, erase the content in your `styles.css` file and add the following code snippet: styles.css ``` .black-img { border: 5px dotted black; border-radius: 10%; } .yellow-img { border: 25px solid yellow; border-radius: 50%; } .red-img { border: 15px double red; } ``` Copy Here you have created CSS rules for three different classes that can be applied to the HTML `<img>` tag. Before you move on, let’s briefly study what we’ve declared in each ruleset: - The first CSS rule declares that the class `black-img` should have a `black`, `dotted` border five pixels wide and a `border-radius` sized at 10%, which gives the element rounded corners. - The second CSS rule declares that the class `yellow-img` should have a `yellow`, `solid` border 25 pixels wide and a `border-radius` sized at 50%, which gives the element a circular shape. - The third CSS rule declares that the class `red-img` should have a `red`, `double` border 15 pixels wide. You have not set a border-radius, so the border will conform to the element’s shape. Save the `styles.css` file. Then erase everything from your `index.html` file (except for the first line of code: `<link rel="stylesheet" href="css/styles.css">`) and add the following code snippet: index.html ``` <img src="https://css.sammy-codes.com/images/small-profile.jpeg" class="black-img"> <img src="https://css.sammy-codes.com/images/small-profile.jpeg" class="yellow-img"> <img src="https://css.sammy-codes.com/images/small-profile.jpeg" class="red-img"> ``` Copy Each of these three lines of HTML code add an image to the HTML document and assign it one of the three classes you just added to the `styles.css` file. Note that you are sourcing the image from an online location. You can also use your own image by specifying the file path as instructed in our tutorial [How To Add Images To Your Webpage With HTML](https://www.digitalocean.com/community/tutorials/how-to-add-images-to-your-webpage-using-html). Save your `index.html` file and load it in the browser. You should receive something like this: ![Webpage with images styled with three classes](https://assets.digitalocean.com/articles/how-to-build-a-website-with-css/image-classes.png) Your webpage should now display three images, each styled with the different specifications of their assigned class. To continue exploring CSS classes, trying creating new classes with different rulesets and applying them to different types of HTML content. Note that properties and values specified in class declaration blocks will only work on elements that they are intended for. For example, a `font-color` declaration will not change the color of an image border. Likewise, a `height` declaration will not change the size of the font. ## [Conclusion](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#conclusion) You have now explored how to create classes, assign them specific property values, and apply them to text and image content. You will return to using classes when you begin building the website in the [second half of this tutorial series](https://www.digitalocean.com/community/tutorials/how-to-set-up-your-css-and-html-website-project). In the next tutorial, you will create CSS *ID* selectors, which work similarly as class selectors with the exception of some unique features. Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases. [Learn more about our products](https://www.digitalocean.com/products "Learn more about our products") ### Tutorial Series: How To Build a Website With CSS This tutorial is part of a series on creating and customizing [this website](http://css.sammy-codes.com/) with CSS, a stylesheet language used to control the presentation of websites. You may follow the entire series to recreate the demonstration website and gain familiarity with CSS or use the methods described here for other CSS website projects. Before proceeding, we recommend that you have some knowledge of HTML, the standard markup language used to display documents in a web browser. If you don’t have familiarity with HTML, you can follow the first ten tutorials of our series [How To Build a Website With HTML](https://www.digitalocean.com/community/tutorial_series/how-to-build-a-website-with-html) before starting this series. [CSS](https://www.digitalocean.com/community/tags/css) [Spin Up](https://www.digitalocean.com/community/tags/spin-up) [Visit series page](https://www.digitalocean.com/community/tutorial-series/how-to-build-a-website-with-css) Browse Series: 20 tutorials - 1/20 - [A Brief Introduction To CSS](https://www.digitalocean.com/community/tutorials/a-brief-introduction-to-css) - 2/20 - [How To Set Up Your CSS and HTML Practice Project With a Code Editor](https://www.digitalocean.com/community/tutorials/how-to-set-up-your-css-and-html-practice-project-with-a-code-editor) - 3/20 - [How To Understand and Create CSS Rules](https://www.digitalocean.com/community/tutorials/how-to-understand-and-create-css-rules) Expand to view all ### About the author ![Erin Glass](https://www.gravatar.com/avatar/a0f19b54dd93645bbb10a0e06719054c5f77c687d9066b70921e3f0aa644d08d?default=retro&size=256) Erin Glass Author Senior Manager, DevEd [See author profile](https://www.digitalocean.com/community/users/eglass) Open source advocate and lover of education, culture, and community. [See author profile](https://www.digitalocean.com/community/users/eglass) Category: [Tutorial](https://www.digitalocean.com/community/tutorials?subtype=tutorial) Tags: [CSS](https://www.digitalocean.com/community/tags/css) [Spin Up](https://www.digitalocean.com/community/tags/spin-up) #### Still looking for an answer? [Ask a question](https://www.digitalocean.com/community/questions)[Search for more help](https://www.digitalocean.com/community) Was this helpful? Yes No Comments(0) Follow-up questions(0) This textbox defaults to using Markdown to format your answer. You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link\! [Sign in/up to comment](https://www.digitalocean.com/api/dynamic-content/v1/login?success_redirect=https%3A%2F%2Fwww.digitalocean.com%2Fcommunity%2Ftutorials%2Fhow-to-create-classes-with-css&error_redirect=https%3A%2F%2Fwww.digitalocean.com%2Fauth-error&type=register) [![Creative Commons](https://www.digitalocean.com/api/static-content/v1/images?src=%2F_next%2Fstatic%2Fmedia%2Fcreativecommons.c0a877f1.png&width=384)](https://creativecommons.org/licenses/by-nc-sa/4.0/)This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License. ## Deploy on DigitalOcean Click below to sign up for DigitalOcean's virtual machines, Databases, and AIML products. [Sign up](https://cloud.digitalocean.com/registrations/new?refcode=f6fcd01aaffb) ## Popular Topics 1. [AI/ML](https://www.digitalocean.com/community/tags/ai-ml) 2. [Ubuntu](https://www.digitalocean.com/community/tags/ubuntu) 3. [Linux Basics](https://www.digitalocean.com/community/tags/linux-basics) 4. [JavaScript](https://www.digitalocean.com/community/tags/javascript) 5. [Python](https://www.digitalocean.com/community/tags/python) 6. [MySQL](https://www.digitalocean.com/community/tags/mysql) 7. [Docker](https://www.digitalocean.com/community/tags/docker) 8. [Kubernetes](https://www.digitalocean.com/community/tags/kubernetes) 9. [All tutorials](https://www.digitalocean.com/community/tutorials) 10. [Talk to an expert](https://www.digitalocean.com/company/contact/sales?referrer=tutorials) ### Connect on Discord Join the conversation in our Discord to connect with fellow developers [Visit Discord](https://discord.gg/digitalocean) ## Featured tutorials 1. [SOLID Design Principles Explained: Building Better Software Architecture](https://www.digitalocean.com/community/tutorials/s-o-l-i-d-the-first-five-principles-of-object-oriented-design) 2. [How To Remove Docker Images, Containers, and Volumes](https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes) 3. [How to Create a MySQL User and Grant Privileges (Step-by-Step)](https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql) - [All tutorials](https://www.digitalocean.com/community/tutorials) - [All topic tags](https://www.digitalocean.com/community/tags) ##### Join the Tech Talk - [Prerequisites](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#prerequisites) - [How CSS Class Selectors Work](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#how-css-class-selectors-work) - [Creating a CSS Class Using a Class Selector](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#creating-a-css-class-using-a-class-selector) - [Adding CSS Classes to Images](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#adding-css-classes-to-images) - [Conclusion](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#conclusion) - ## Deploy on DigitalOcean Click below to sign up for DigitalOcean's virtual machines, Databases, and AIML products. [Sign up](https://cloud.digitalocean.com/registrations/new?refcode=f6fcd01aaffb) ## Popular Topics 1. [AI/ML](https://www.digitalocean.com/community/tags/ai-ml) 2. [Ubuntu](https://www.digitalocean.com/community/tags/ubuntu) 3. [Linux Basics](https://www.digitalocean.com/community/tags/linux-basics) 4. [JavaScript](https://www.digitalocean.com/community/tags/javascript) 5. [Python](https://www.digitalocean.com/community/tags/python) 6. [MySQL](https://www.digitalocean.com/community/tags/mysql) 7. [Docker](https://www.digitalocean.com/community/tags/docker) 8. [Kubernetes](https://www.digitalocean.com/community/tags/kubernetes) 9. [All tutorials](https://www.digitalocean.com/community/tutorials) 10. [Talk to an expert](https://www.digitalocean.com/company/contact/sales?referrer=tutorials) ### Connect on Discord Join the conversation in our Discord to connect with fellow developers [Visit Discord](https://discord.gg/digitalocean) ## Featured tutorials 1. [SOLID Design Principles Explained: Building Better Software Architecture](https://www.digitalocean.com/community/tutorials/s-o-l-i-d-the-first-five-principles-of-object-oriented-design) 2. [How To Remove Docker Images, Containers, and Volumes](https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes) 3. [How to Create a MySQL User and Grant Privileges (Step-by-Step)](https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql) - [All tutorials](https://www.digitalocean.com/community/tutorials) - [All topic tags](https://www.digitalocean.com/community/tags) ![](https://www.digitalocean.com/api/static-content/v1/images?src=%2F_next%2Fstatic%2Fmedia%2Ftutorials-2-tulip.764b9f59.svg&width=1920) ## Become a contributor for community Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation. [Sign Up](https://www.digitalocean.com/community/pages/write-for-digitalocean) ![](https://www.digitalocean.com/api/static-content/v1/images?src=%2F_next%2Fstatic%2Fmedia%2Fdocs-2-kiwi.239a03ef.svg&width=1920) ## DigitalOcean Documentation Full documentation for every DigitalOcean product. [Learn more](https://docs.digitalocean.com/) ![](https://www.digitalocean.com/api/static-content/v1/images?src=%2F_next%2Fstatic%2Fmedia%2Fblogs-1-lavender.495d1f00.svg&width=1920) ## Resources for startups and AI-native businesses The Wave has everything you need to know about building a business, from raising funding to marketing your product. [Learn more](https://www.digitalocean.com/resources) ## Get our newsletter Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter. New accounts only. By submitting your email you agree to our [Privacy Policy](https://www.digitalocean.com/legal/privacy-policy) ## The developer cloud Scale up as you grow — whether you're running one virtual machine or ten thousand. [View all products](https://www.digitalocean.com/products) ![](https://www.digitalocean.com/api/static-content/v1/images?src=%2F_next%2Fstatic%2Fmedia%2Fclouds-mobile.5d14bead.svg&width=3840) ## Get started for free Sign up and get \$200 in credit for your first 60 days with DigitalOcean.\* [Get started](https://cloud.digitalocean.com/registrations/new?refcode=f6fcd01aaffb) ![](https://www.digitalocean.com/api/static-content/v1/images?src=%2F_next%2Fstatic%2Fmedia%2Fwaves-mobile.a054c63e.svg&width=3840) \*This promotional offer applies to new accounts only. ## Company - [About](https://www.digitalocean.com/about) - [Leadership](https://www.digitalocean.com/leadership/executive-management) - [Blog](https://www.digitalocean.com/blog) - [Careers](https://www.digitalocean.com/careers) - [Customers](https://www.digitalocean.com/customers) - [Partners](https://www.digitalocean.com/partners) - [Referral Program](https://www.digitalocean.com/referral-program) - [Affiliate Program](https://www.digitalocean.com/affiliates) - [Press](https://www.digitalocean.com/press) - [Legal](https://www.digitalocean.com/legal) - [Privacy Policy](https://www.digitalocean.com/legal/privacy-policy) - [Security](https://www.digitalocean.com/security) - [Investor Relations](https://investors.digitalocean.com/) ## Products - [Overview](https://www.digitalocean.com/products) - [Droplets](https://www.digitalocean.com/products/droplets) - [Kubernetes](https://www.digitalocean.com/products/kubernetes) - [Functions](https://www.digitalocean.com/products/functions) - [App Platform](https://www.digitalocean.com/products/app-platform) - [Gradient™ AI GPU Droplets](https://www.digitalocean.com/products/gradient/gpu-droplets) - [Gradient™ AI Bare Metal GPUs](https://www.digitalocean.com/products/gradient/bare-metal-gpus) - [Gradient™ AI 1-Click Models](https://www.digitalocean.com/products/gradient/1-click-models) - [Gradient™ AI Platform](https://www.digitalocean.com/products/gradient/platform) - [Load Balancers](https://www.digitalocean.com/products/load-balancers) - [Managed Databases](https://www.digitalocean.com/products/managed-databases) - [Spaces](https://www.digitalocean.com/products/spaces) - [Block Storage](https://www.digitalocean.com/products/block-storage) - [Network File Storage](https://www.digitalocean.com/products/storage/network-file-storage) - [API](https://docs.digitalocean.com/reference/api) - [Uptime](https://www.digitalocean.com/products/uptime-monitoring) - [Identity and Access Management](https://www.digitalocean.com/products/identity-access-management) - [Cloudways](https://www.digitalocean.com/products/cloudways) ## Resources - [Community Tutorials](https://www.digitalocean.com/community/tutorials) - [Community Q\&A](https://www.digitalocean.com/community/questions) - [CSS-Tricks](https://css-tricks.com/) - [Write for DOnations](https://www.digitalocean.com/community/pages/write-for-digitalocean) - [Currents Research](https://www.digitalocean.com/currents) - [DigitalOcean Startups](https://www.digitalocean.com/startups) - [Wavemakers Program](https://www.digitalocean.com/wavemakers) - [Compass Council](https://www.digitalocean.com/research) - [Open Source](https://www.digitalocean.com/open-source) - [Newsletter Signup](https://www.digitalocean.com/community#iaan) - [Marketplace](https://www.digitalocean.com/products/marketplace) - [Pricing](https://www.digitalocean.com/pricing) - [Pricing Calculator](https://www.digitalocean.com/pricing/calculator) - [Documentation](https://docs.digitalocean.com/) - [Release Notes](https://docs.digitalocean.com/release-notes) - [Code of Conduct](https://www.digitalocean.com/community/pages/code-of-conduct) - [Shop Swag](http://store.digitalocean.com/) ## Solutions - [Website Hosting](https://www.digitalocean.com/solutions/website-hosting) - [VPS Hosting](https://www.digitalocean.com/solutions/vps-hosting) - [Web & Mobile Apps](https://www.digitalocean.com/solutions/web-mobile-apps) - [Game Development](https://www.digitalocean.com/solutions/gaming-development) - [Streaming](https://www.digitalocean.com/solutions/streaming) - [VPN](https://www.digitalocean.com/solutions/vpn) - [SaaS Platforms](https://www.digitalocean.com/solutions/saas) - [Cloud Hosting for Blockchain](https://www.digitalocean.com/solutions/blockchain) - [Startup Resources](https://www.digitalocean.com/resources) - [Migration Assistance](https://www.digitalocean.com/migrate) ## Contact - [Support](https://www.digitalocean.com/support) - [Sales](https://www.digitalocean.com/company/contact/sales?referrer=footer) - [Report Abuse](https://www.digitalocean.com/company/contact/abuse) - [System Status](https://status.digitalocean.com/) - [Share your ideas](https://ideas.digitalocean.com/) ## Company - [About](https://www.digitalocean.com/about) - [Leadership](https://www.digitalocean.com/leadership/executive-management) - [Blog](https://www.digitalocean.com/blog) - [Careers](https://www.digitalocean.com/careers) - [Customers](https://www.digitalocean.com/customers) - [Partners](https://www.digitalocean.com/partners) - [Referral Program](https://www.digitalocean.com/referral-program) - [Affiliate Program](https://www.digitalocean.com/affiliates) - [Press](https://www.digitalocean.com/press) - [Legal](https://www.digitalocean.com/legal) - [Privacy Policy](https://www.digitalocean.com/legal/privacy-policy) - [Security](https://www.digitalocean.com/security) - [Investor Relations](https://investors.digitalocean.com/) ## Products - [Overview](https://www.digitalocean.com/products) - [Droplets](https://www.digitalocean.com/products/droplets) - [Kubernetes](https://www.digitalocean.com/products/kubernetes) - [Functions](https://www.digitalocean.com/products/functions) - [App Platform](https://www.digitalocean.com/products/app-platform) - [Gradient™ AI GPU Droplets](https://www.digitalocean.com/products/gradient/gpu-droplets) - [Gradient™ AI Bare Metal GPUs](https://www.digitalocean.com/products/gradient/bare-metal-gpus) - [Gradient™ AI 1-Click Models](https://www.digitalocean.com/products/gradient/1-click-models) - [Gradient™ AI Platform](https://www.digitalocean.com/products/gradient/platform) - [Load Balancers](https://www.digitalocean.com/products/load-balancers) - [Managed Databases](https://www.digitalocean.com/products/managed-databases) - [Spaces](https://www.digitalocean.com/products/spaces) - [Block Storage](https://www.digitalocean.com/products/block-storage) - [Network File Storage](https://www.digitalocean.com/products/storage/network-file-storage) - [API](https://docs.digitalocean.com/reference/api) - [Uptime](https://www.digitalocean.com/products/uptime-monitoring) - [Identity and Access Management](https://www.digitalocean.com/products/identity-access-management) - [Cloudways](https://www.digitalocean.com/products/cloudways) ## Resources - [Community Tutorials](https://www.digitalocean.com/community/tutorials) - [Community Q\&A](https://www.digitalocean.com/community/questions) - [CSS-Tricks](https://css-tricks.com/) - [Write for DOnations](https://www.digitalocean.com/community/pages/write-for-digitalocean) - [Currents Research](https://www.digitalocean.com/currents) - [DigitalOcean Startups](https://www.digitalocean.com/startups) - [Wavemakers Program](https://www.digitalocean.com/wavemakers) - [Compass Council](https://www.digitalocean.com/research) - [Open Source](https://www.digitalocean.com/open-source) - [Newsletter Signup](https://www.digitalocean.com/community#iaan) - [Marketplace](https://www.digitalocean.com/products/marketplace) - [Pricing](https://www.digitalocean.com/pricing) - [Pricing Calculator](https://www.digitalocean.com/pricing/calculator) - [Documentation](https://docs.digitalocean.com/) - [Release Notes](https://docs.digitalocean.com/release-notes) - [Code of Conduct](https://www.digitalocean.com/community/pages/code-of-conduct) - [Shop Swag](http://store.digitalocean.com/) ## Solutions - [Website Hosting](https://www.digitalocean.com/solutions/website-hosting) - [VPS Hosting](https://www.digitalocean.com/solutions/vps-hosting) - [Web & Mobile Apps](https://www.digitalocean.com/solutions/web-mobile-apps) - [Game Development](https://www.digitalocean.com/solutions/gaming-development) - [Streaming](https://www.digitalocean.com/solutions/streaming) - [VPN](https://www.digitalocean.com/solutions/vpn) - [SaaS Platforms](https://www.digitalocean.com/solutions/saas) - [Cloud Hosting for Blockchain](https://www.digitalocean.com/solutions/blockchain) - [Startup Resources](https://www.digitalocean.com/resources) - [Migration Assistance](https://www.digitalocean.com/migrate) ## Contact - [Support](https://www.digitalocean.com/support) - [Sales](https://www.digitalocean.com/company/contact/sales?referrer=footer) - [Report Abuse](https://www.digitalocean.com/company/contact/abuse) - [System Status](https://status.digitalocean.com/) - [Share your ideas](https://ideas.digitalocean.com/) © 2026 DigitalOcean, LLC.[Sitemap](https://www.digitalocean.com/sitemap).[Cookie Preferences]() This site uses cookies and related technologies, as described in our [privacy policy](https://www.digitalocean.com/legal/privacy-policy/), for purposes that may include site operation, analytics, enhanced user experience, or advertising. You may choose to consent to our use of these technologies, or manage your own preferences. Please visit our [cookie policy](https://www.digitalocean.com/legal/cookie-policy) for more information. Agree & Proceed Decline All Manage Choices Loading... ## Community ## Product Docs ## Marketplace ## DigitalOcean Blog navigate go exit
Readable Markdown
### [Introduction](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#introduction) In this tutorial, you will create a CSS *class* selector, which will allow you to apply CSS rules only to HTML elements that are assigned the class. CSS class selectors are useful when you want to apply different style rules for different instances of the same HTML element. ## [Prerequisites](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#prerequisites) To follow this tutorial, make sure you have set up the necessary files and folders as instructed in a previous tutorial in this series [How To Set Up You CSS and HTML Practice Project](https://www.digitalocean.com/community/tutorials/how-to-set-up-your-css-and-html-practice-project). ## [How CSS Class Selectors Work](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#how-css-class-selectors-work) A CSS class selector allows you to assign style rules to HTML elements that you designate with that class rather than *all* instances of a certain element. Unlike HTML elements (such as `<p>`, `<h1>` or `<img>`), whose names are predetermined, class names are chosen by the developer when they create the class. Class names are always preceded by a `.`, which can help you distinguish between tag selectors and class selectors in CSS files. A CSS rule for a class selector is written in the same way as a rule for a tag selector, with the exception of the `.` prepended to the class name: ``` .red-text { color: red; } ``` To use a class when adding HTML content to your webpage, you must specify it in the opening tag of an HTML element using the class [attribute](https://www.digitalocean.com/community/tutorials/how-to-use-html-attributes) in your HTML document like so: ``` <h1 class=".red-text ">Content.</element> ``` ## [Creating a CSS Class Using a Class Selector](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#creating-a-css-class-using-a-class-selector) Let’s begin exploring CSS classes in practice. Erase everything in your `styles.css` file and add the following code snippet to specify a rule for the class `red-text`: styles.css ``` .red-text { color: red; } ``` After adding the code snippet to your `styles.css` file, save the file. Return to your `index.html` and erase everything but the first line of code `<link rel="stylesheet" href="css/styles.css">` that links to your CSS stylesheet. Then add the following HTML code snippet: index.html ``` <p class="red-text ">Here is the first sample of paragraph text.</p> ``` Note that the class name is not prepended here with a `.` as it is when being used as a selector for a CSS rule. Your entire `index.html` file should have the following contents: index.html ``` . . . <link rel="stylesheet" href="css/styles.css"> <p class="red-text" Here is the first sample of paragraph text.</p> ``` In this code snippet you have added text using the HTML `<p>` tag. But you have also specified the `red-text` class by adding the highlighted class [attribute](https://www.digitalocean.com/community/tutorials/how-to-use-html-attributes) `class="red-text"` *inside* the opening HTML tag. Save your `index.html` file and load it in the browser. (For instructions on loading an HTML file, please visit our tutorial step [How To View An Offline HTML File In Your Browser](https://www.digitalocean.com/community/tutorials/how-to-use-and-understand-html-elements#how-to-view-an-offline-html-file-in-your-browser)). You should receive a webpage with red text: ![Webpage output with red paragraph text](https://assets.digitalocean.com/articles/how-to-build-a-website-with-css/red-text.png) Let’s add an additional CSS class to explore styling different pieces of `<p>` text content with different classes. Add the following code snippet to your `styles.css` file (after your CSS rule for “red-text”): styles.css ``` .yellow-background-text { background-color: yellow; } ``` This CSS rule declares that the class `yellow-background-text` is assigned the `yellow` value for the `background-color` property. Any HTML text element assigned this class will have a yellow background. Note that the use of the word `text`in the class `yellow-background-*text*` is for human readability purposes only. You do not need to include the word `text` in your class names for classes assigned to HTML text. To apply this new CSS class, return to your `index.html` file and add the following line of code to the bottom: index.html ``` <p class="yellow-background-text"> Here is the second sample of paragraph text.<p> ``` In this code snippet, you have added some text content with the `<p>` element and specified the `yellow-background-text` class. Save the file and reload it in your browser. You should have a webpage with two different sentences, the first one red and the second one with a yellow background: ![Webpage with text styled by two classes](https://assets.digitalocean.com/articles/how-to-build-a-website-with-css/two-classes.png) Note that you can add more than one class to an HTML tag. Try adding both classes to a single text element by adding the following line to your `index.html` file: index.html ``` <p class="red-text yellow-background-text">Here is a third sample of text.</p> ``` Note that the class names are only separated by a space. Save the file and reload it in the browser. You should receive something like this: ![IWebpage with text styled by three classes](https://assets.digitalocean.com/articles/how-to-build-a-website-with-css/three-classes.png) Your third line of text should now be styled according to the property values set in the `red-text` class and the `yellow-background-text` class and have a red font and yellow background. ## [Adding CSS Classes to Images](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#adding-css-classes-to-images) CSS classes can also be applied to other HTML elements, such as images. To explore using CSS classes for images, erase the content in your `styles.css` file and add the following code snippet: styles.css ``` .black-img { border: 5px dotted black; border-radius: 10%; } .yellow-img { border: 25px solid yellow; border-radius: 50%; } .red-img { border: 15px double red; } ``` Here you have created CSS rules for three different classes that can be applied to the HTML `<img>` tag. Before you move on, let’s briefly study what we’ve declared in each ruleset: - The first CSS rule declares that the class `black-img` should have a `black`, `dotted` border five pixels wide and a `border-radius` sized at 10%, which gives the element rounded corners. - The second CSS rule declares that the class `yellow-img` should have a `yellow`, `solid` border 25 pixels wide and a `border-radius` sized at 50%, which gives the element a circular shape. - The third CSS rule declares that the class `red-img` should have a `red`, `double` border 15 pixels wide. You have not set a border-radius, so the border will conform to the element’s shape. Save the `styles.css` file. Then erase everything from your `index.html` file (except for the first line of code: `<link rel="stylesheet" href="css/styles.css">`) and add the following code snippet: index.html ``` <img src="https://css.sammy-codes.com/images/small-profile.jpeg" class="black-img"> <img src="https://css.sammy-codes.com/images/small-profile.jpeg" class="yellow-img"> <img src="https://css.sammy-codes.com/images/small-profile.jpeg" class="red-img"> ``` Each of these three lines of HTML code add an image to the HTML document and assign it one of the three classes you just added to the `styles.css` file. Note that you are sourcing the image from an online location. You can also use your own image by specifying the file path as instructed in our tutorial [How To Add Images To Your Webpage With HTML](https://www.digitalocean.com/community/tutorials/how-to-add-images-to-your-webpage-using-html). Save your `index.html` file and load it in the browser. You should receive something like this: ![Webpage with images styled with three classes](https://assets.digitalocean.com/articles/how-to-build-a-website-with-css/image-classes.png) Your webpage should now display three images, each styled with the different specifications of their assigned class. To continue exploring CSS classes, trying creating new classes with different rulesets and applying them to different types of HTML content. Note that properties and values specified in class declaration blocks will only work on elements that they are intended for. For example, a `font-color` declaration will not change the color of an image border. Likewise, a `height` declaration will not change the size of the font. ## [Conclusion](https://www.digitalocean.com/community/tutorials/how-to-create-classes-with-css#conclusion) You have now explored how to create classes, assign them specific property values, and apply them to text and image content. You will return to using classes when you begin building the website in the [second half of this tutorial series](https://www.digitalocean.com/community/tutorials/how-to-set-up-your-css-and-html-website-project). In the next tutorial, you will create CSS *ID* selectors, which work similarly as class selectors with the exception of some unique features. Was this helpful? [![Creative Commons](https://www.digitalocean.com/api/static-content/v1/images?src=%2F_next%2Fstatic%2Fmedia%2Fcreativecommons.c0a877f1.png&width=384)](https://creativecommons.org/licenses/by-nc-sa/4.0/)This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
Shard83 (laksa)
Root Hash13428457316079428483
Unparsed URLcom,digitalocean!www,/community/tutorials/how-to-create-classes-with-css s443