search
HomeWeb Front-endCSS TutorialThere are several ways to express colors in css

There are 6 ways to express colors in css, which are: 1. English words, such as red, blue; 2. Hexadecimal values, such as "#FF0000"; 3. RGB, such as "RGB( 255,0,0)"; 4. RGBA, for example "RGB(255,0,0,0.5)"; 5. HSL; 6. HSLA.

There are several ways to express colors in css

#The operating environment of this tutorial: Windows 7 system, css3 version, Dell G3 computer.

Tutorial recommendation: css video tutorial

Several expressions of color in css

1. Define color, use English words to represent colors; such as red, blue, etc.

2, hexadecimal value

three-digit hexadecimal; such as #F00 (each color Represented by one hexadecimal number)

Six-digit hexadecimal number; such as #FF0000 (each color is represented by two hexadecimal numbers)

3. RGB expression Method

RGB three primary colors: RGB(255,0,0) The given three parameters represent the color values ​​​​of red, green, and blue, expressed in decimal from 0 to 225

RGB, RGB (100%, 0%, 0%), use the percent sign to express

Note: The above expressions all belong to the RGB color system (red, green, blue)

4 , RGBA: Same as RGB, just with an additional transparency, such as RGB(255,0,0,0.5). The fourth value range is 0-1, 0 is completely transparent, 1 is completely opaque

5, HSL (more used for learning later color adjustment): hue, saturation, brightness. For example, HSL(360,100%,50%).

Hue: It is the basic attribute of color, which is the name of the color commonly referred to, such as red, etc.

Saturation: refers to the purity of the color. The higher the color, the purer the color, and the lower it gradually becomes. Gray, take the value of 0-100%

Brightness: It is the brightness of the color. The higher the brightness of the color, the brighter the color; the darker the brightness of the color, the darker the color. Take 0-100%.

(When you want the page to use a color system, you can use HSL)

6. HSLA: It has more transparency than HSL.

Usage:

①color:blue;

The first method is to call the color attribute and enter the English word of the color after the colon to separate The number ends.

This method is straightforward, but there are very few types of colors that can be represented.

②color:#000000;

The second type, starting with '#', each digit can be: 0, 1, 2, 3, 4, 5, 6, 7, 8 ,

9, a, b, c, d, e, f. The first 1 and 2 digits represent red, 3 and 4 digits represent green, and 5 and 6

represent blue. Similar to the idea of ​​RGB color representation, the three primary colors of red, green and blue are combined into

various colors, and there are many types.

③color:rgb(0,0,0);

The third method is RGB representation. There are two types of values: numerical value, all values ​​are 0-255; percentage value

, all values ​​are 0%-100%. Their common feature is that the first value represents red, the second

value represents green, and the third value represents blue. Through combination, various colors can be represented.

④color:rgba(0,0,0,0.5);

The fourth method is RGBA representation. It is an upgraded version of RGB representation and adds a new transparency attribute.

The first three attribute values ​​are the same as RGB notation. The value range of the fourth attribute value is 0-1 which can be

accurate to two decimal places.

⑤color:hsl (0, 100%, 100%);

The fifth method, HSL representation. Its meaning: H represents hue, the value range is 0-

360, 0 and 360 represent red, 120 represents green, and 240 represents blue. S represents saturation

, the value range is 0%-100%. L represents brightness, the value range is 0%-100%.

⑥color:hsla(0,100%,100%,0.5);

Sixth, HSLA representation. It is an enhanced version of HSL notation, adding the attribute

value of transparency, with a value range of 0-1.

For more programming-related knowledge, please visit: Programming Teaching! !

The above is the detailed content of There are several ways to express colors in css. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
This Isn't Supposed to Happen: Troubleshooting the ImpossibleThis Isn't Supposed to Happen: Troubleshooting the ImpossibleMay 15, 2025 am 10:32 AM

What it looks like to troubleshoot one of those impossible issues that turns out to be something totally else you never thought of.

@keyframes vs CSS Transitions: What is the difference?@keyframes vs CSS Transitions: What is the difference?May 14, 2025 am 12:01 AM

@keyframesandCSSTransitionsdifferincomplexity:@keyframesallowsfordetailedanimationsequences,whileCSSTransitionshandlesimplestatechanges.UseCSSTransitionsforhovereffectslikebuttoncolorchanges,and@keyframesforintricateanimationslikerotatingspinners.

Using Pages CMS for Static Site Content ManagementUsing Pages CMS for Static Site Content ManagementMay 13, 2025 am 09:24 AM

I know, I know: there are a ton of content management system options available, and while I've tested several, none have really been the one, y'know? Weird pricing models, difficult customization, some even end up becoming a whole &

The Ultimate Guide to Linking CSS Files in HTMLThe Ultimate Guide to Linking CSS Files in HTMLMay 13, 2025 am 12:02 AM

Linking CSS files to HTML can be achieved by using elements in part of HTML. 1) Use tags to link local CSS files. 2) Multiple CSS files can be implemented by adding multiple tags. 3) External CSS files use absolute URL links, such as. 4) Ensure the correct use of file paths and CSS file loading order, and optimize performance can use CSS preprocessor to merge files.

CSS Flexbox vs Grid: a comprehensive reviewCSS Flexbox vs Grid: a comprehensive reviewMay 12, 2025 am 12:01 AM

Choosing Flexbox or Grid depends on the layout requirements: 1) Flexbox is suitable for one-dimensional layouts, such as navigation bar; 2) Grid is suitable for two-dimensional layouts, such as magazine layouts. The two can be used in the project to improve the layout effect.

How to Include CSS Files: Methods and Best PracticesHow to Include CSS Files: Methods and Best PracticesMay 11, 2025 am 12:02 AM

The best way to include CSS files is to use tags to introduce external CSS files in the HTML part. 1. Use tags to introduce external CSS files, such as. 2. For small adjustments, inline CSS can be used, but should be used with caution. 3. Large projects can use CSS preprocessors such as Sass or Less to import other CSS files through @import. 4. For performance, CSS files should be merged and CDN should be used, and compressed using tools such as CSSNano.

Flexbox vs Grid: should I learn them both?Flexbox vs Grid: should I learn them both?May 10, 2025 am 12:01 AM

Yes,youshouldlearnbothFlexboxandGrid.1)Flexboxisidealforone-dimensional,flexiblelayoutslikenavigationmenus.2)Gridexcelsintwo-dimensional,complexdesignssuchasmagazinelayouts.3)Combiningbothenhanceslayoutflexibilityandresponsiveness,allowingforstructur

Orbital Mechanics (or How I Optimized a CSS Keyframes Animation)Orbital Mechanics (or How I Optimized a CSS Keyframes Animation)May 09, 2025 am 09:57 AM

What does it look like to refactor your own code? John Rhea picks apart an old CSS animation he wrote and walks through the thought process of optimizing it.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.