Color in HTML (2024)

Colors in HTML can be specified using:

  1. a color name. HTML used to recognize 16 color names ("black", "white", "gray", "silver", "maroon", "red", "purple", "fushsia", "green", "lime", "olive", "yellow", "navy", "blue", "teal", and "aqua"), but new browsers can recognize 147 CSS3 color names.
  2. a color number, such as "#FF0000", "#FFFFFF" (those are red and white).

Color Numbers

Color numbers are specified using hexadecimal (base 16) values.

The hexidecimal digits are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
(where A through F equal the base 10 numbers: 10, 11, 12, 13, 14, 15)

The six digit color number is broken into three groups of two digits which specify the amount of Red, Green, and Blue in the color (using additive color...the way colored lights mix, not the way color pigments mix). Each two digit hex pair can have a value from 00 to FF (FF=256 in base 10). This gives over 16 million possible colors.

For example:

#FF0000 means FF worth of Red, and no Green or Blue. The result is RED.

#0000FF means no Red or Green, and FF worth of Blue. The result is BLUE.

#FFFF00 means FF worth of Red and Green, and Blue. The result is YELLOW.

#000000 means no Red, Green, or Blue. The result is BLACK.

#FFFFFF means full FF amounts of Red, Green, and Blue. The result is WHITE.

#FFEFD5 has high values for all colors, giving a light result: PAPAYAWHIP.
(no, I don't know who thought up the color names.)

#556B2F has lower values for all colors, giving a darker result: DARKOLIVEGREEN.

Note that is is OK to use either uppercase or lowercase letters for the base-16 digits A, B, C, D, E, F.

HTML also recognizes color numbers that contain just three hexidecimal digits. This is a shortcut for colors where the red, green, and blue values consist of two identical digits. Example:

#00F is the same as: #0000FF and is BLUE.

#FF0 is the same as: #FFFF00 and isYELLOW.

#6B5 is the same as: #66BB55 and is THIS COLOR.

#000 is BLACK. #FFF is WHITE.

#666 is a DARK GRAY. #AAA is a light LIGHT GRAY.

NOTE! Always remember to put in the # symbol when specifying color numbers. Older versions of HTML didn't care if you left it out, but some browsers are stricter about this, and f you forget the # sign the browser may not display the color you requested.

Web Safe Colors

Nowadays, computers/monitors can display thousands or millions of colors, so the concept of "Web safe colors" is no longer important. But years ago, many computers were limited to displaying "8-bit color" and could only show 256 possible colors. Even worse, different computer systems (PC, Mac, UNIX workstations) don't even use the same 256 colors in their "color palettes," so you couldn't be sure what your color will be shifted to.

To avoid problems for older machines and different system color palettes, early Web designers usually limited their color choices to the 216 "web safe colors" which would display more or less the same on all systems. The web safe colors use only the hex values 00, 33, 66, 99, CC, and FF when making color combinations.

Of the examples shown earlier,

#FFEFD5 (PAPAYAWHIP)and

#556B2F (DARKOLIVEGREEN)

...are not web safe colors. They would get shifted to

#FFFFCC (NOT PAPAYAWHIP)and

#666633 (NOT DARKOLIVEGREEN)

...on ancient systems.

Below are six tables showing all of the 216 "web safe" colors, just to show you a range of colors compared to their hex values.

Within each table, red increases from left to right, and green increases from top to bottom, in steps of 33 (hex).

Blue increases from the first table to the last, in steps of 33 (hex).

#000000#330000#660000#990000#CC0000#FF0000
#003300#333300#663300#993300#CC3300#FF3300
#006600#336600#666600#996600#CC6600#FF6600
#009900#339900#669900#999900#CC9900#FF9900
#00CC00#33CC00#66CC00#99CC00#CCCC00#FFCC00
#00FF00#33FF00#66FF00#99FF00#CCFF00#FFFF00

#000033#330033#660033#990033#CC0033#FF0033
#003333#333333#663333#993333#CC3333#FF3333
#006633#336633#666633#996633#CC6633#FF6633
#009933#339933#669933#999933#CC9933#FF9933
#00CC33#33CC33#66CC33#99CC33#CCCC33#FFCC33
#00FF33#33FF33#66FF33#99FF33#CCFF33#FFFF33

#000066#330066#660066#990066#CC0066#FF0066
#003366#333366#663366#993366#CC3366#FF3366
#006666#336666#666666#996666#CC6666#FF6666
#009966#339966#669966#999966#CC9966#FF9966
#00CC66#33CC66#66CC66#99CC66#CCCC66#FFCC66
#00FF66#33FF66#66FF66#99FF66#CCFF66#FFFF66

#000099#330099#660099#990099#CC0099#FF0099
#003399#333399#663399#993399#CC3399#FF3399
#006699#336699#666699#996699#CC6699#FF6699
#009999#339999#669999#999999#CC9999#FF9999
#00CC99#33CC99#66CC99#99CC99#CCCC99#FFCC99
#00FF99#33FF99#66FF99#99FF99#CCFF99#FFFF99

#0000CC#3300CC#6600CC#9900CC#CC00CC#FF00CC
#0033CC#3333CC#6633CC#9933CC#CC33CC#FF33CC
#0066CC#3366CC#6666CC#9966CC#CC66CC#FF66CC
#0099CC#3399CC#6699CC#9999CC#CC99CC#FF99CC
#00CCCC#33CCCC#66CCCC#99CCCC#CCCCCC#FFCCCC
#00FFCC#33FFCC#66FFCC#99FFCC#CCFFCC#FFFFCC

#0000FF#3300FF#6600FF#9900FF#CC00FF#FF00FF
#0033FF#3333FF#6633FF#9933FF#CC33FF#FF33FF
#0066FF#3366FF#6666FF#9966FF#CC66FF#FF66FF
#0099FF#3399FF#6699FF#9999FF#CC99FF#FF99FF
#00CCFF#33CCFF#66CCFF#99CCFF#CCCCFF#FFCCFF
#00FFFF#33FFFF#66FFFF#99FF9FF#CCFFFF#FFFFFF
Color in HTML (2024)

FAQs

How do you color all text in HTML? ›

We use the style attribute to set the font color in HTML. The style attribute specifies an inline style for an element, with the CSS property color. The attribute is used with the HTML <p> tag, with the CSS property color. HTML5 do not support the <font> tag, so the CSS style is used to add font color.

What are the acceptable colors for HTML? ›

The World Wide Web Consortium (W3C) has listed 16 valid color names for HTML and CSS: aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, purple, red, silver, teal, white, and yellow.

How do you specify color code in HTML? ›

You can specify colors on page level using <body> tag or you can set colors for individual tags using bgcolor attribute. bgcolor − sets a color for the background of the page. text − sets a color for the body text. alink − sets a color for active links or selected links.

How do you color only one word in a sentence in HTML? ›

To colored just one word you can use <span style="your style"> WORD</span> . This way you don't have to style the whole paragraph. Example: <p> The quick brown <span style="color: brown">fox</span> jumps over... </p> .

How do I color an entire HTML page? ›

How to Add Background Color in HTML. To add background color in HTML, use the CSS background-color property. Set it to the color name or code you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a table, heading, div, or span tag.

How to change text color in HTML without CSS? ›

Step 1: Firstly, we have to type the Html code in any text editor or open the existing Html file in the text editor in which we want to use the Html tag. Step 2: Now, move the cursor at the starting of that text whose color we want to change. And then, type the empty Html <font> tag at that position.

What does ff0000 mean? ›

The color red with hexadecimal color code #ff0000 / #f00 is a shade of red. In the RGB color model #ff0000 is comprised of 100% red, 0% green and 0% blue. In the HSL color space #ff0000 has a hue of 0° (degrees), 100% saturation and 50% lightness. This color has an approximate wavelength of 611.37 nm.

What is a web safe color? ›

Web safe colors are sets of colors that will not be altered (dithered) when shown on browsers running on a 256-color browser. These sets of colors are initially selected by Netscape for use on their browsers.

How do you highlight specific text in HTML? ›

The <mark> tag defines text that should be marked or highlighted.

How do I color specific text in CSS? ›

Simply add the appropriate CSS selector and define the color property with the value you want. For example, say you want to change the color of all paragraphs on your site to navy. Then you'd add p {color: #000080; } to the head section of your HTML file.

How do you color one paragraph in HTML? ›

The most common way of coloring HTML text is by using hexadecimal color codes (Hex code for short). Simply add a style attribute to the text element you want to color – a paragraph in the example below – and use the color property with your Hex code.

How do I change the color of my text? ›

To change the keyboard color on an Android phone, go to Settings > System > Languages & Input > On-screen keyboard > Gboard > Theme and pick a color.

How do I make text blue in HTML? ›

To specify bright blue, use #0000ff. For purple, use #ff00ff.

How to use bgcolor attribute in HTML? ›

In HTML, the bgcolor attribute sets the background color of a HTML element. The bgcolor attribute can be used with the HTML tags like <body>, <table>, <marquee>, <td>, <tr>, <th>. Pencil: Deprecated warning: HTML5 does not support the bgcolor attribute. It is recommended to use CSS instead.

Can we change the color of text in HTML? ›

The HTML style attribute is used to add styles to an element, such as color, font, size, and more.

How do I change font color and style in HTML? ›

You can change the color and size of your text right inside its tag with the color and font-size properties. This is known as inline CSS. You do it with the style attribute in HTML.

How to color code command line? ›

To set the default Command Prompt window color, select the upper-left corner of the Command Prompt window, select Defaults, select the Colors tab, and then select the colors that you want to use for the Screen Text and Screen Background.

What color is #00000? ›

#000000 means no Red, Green, or Blue. The result is BLACK. #FFFFFF means full FF amounts of Red, Green, and Blue.

What color is #ff 0000? ›

#FF0000 (Red) HTML Color Code.

What color is #00ff00? ›

#00ff00 (light green) info, conversion, color schemes and complementary.

What is the 6 digit color code? ›

What is a hex color code? A hex color code is a 6-symbol code made of up to three 2-symbol elements. Each of the 2-symbol elements expresses a color value from 0 to 255. The code is written using a formula that turns each value into a unique 2-digit alphanumeric code.

What is a hex code? ›

What is a hex code? Hex color codes are one type of HTML color code that you'll often hear referred to as hexadecimal color or hex. The reason to use hexadecimal numbers is it's a human-friendly representation of values in binary code.

What are color codes called? ›

A color hex code is a hexadecimal way to represent a color in RGB format by combining three values – the amounts of red, green and blue in a particular shade of color.

What is the color code for #0000ff? ›

Blue - #0000ff Hex Code, Shades and Complementary Colors.

What HTML colors are #333? ›

Dark charcoal / #333333 / #333 Hex Color Code.

How do I color a specific row in HTML? ›

The background color of the table is given by the bgcolor="color" attribute. When applied to the <table> tag, the color fills the background. Cell background colors are set by applying the bgcolor attribute to a <tr> tag (to color the row) or to a <td> tag (to color the cell).

Can I use relative color syntax? ›

Relative color syntax only applies to the modern (space separated components, / separator for alpha) syntax. It cannot be used with legacy color syntax and attempting to do so is an error.

What makes HTML dynamic? ›

The term “dynamic HTML page” refers to an HTML page because it may be customized and altered based on input from the user. For example, when a person clicks on a button on a web page, the page's background colour changes.

How do I conditionally display text in HTML? ›

Conditional elements are supported in HTML Forms by using two special attributes: data-show-if and data-hide-if . Using these attributes allows you to hide or show parts of your form by referencing the name attribute of a field in your form.

How to customize text using CSS? ›

You simply determine the element that you want to change the font of with a CSS selector, add the font-family property, and include the name of the font as the value. Values can either be font family names like Arial and "Open Sans" or generic font declarations such as serif or monospace .

How do you change both font and color in HTML? ›

You can use a <basefont> tag to set all of your text to the same size, face, and color. The font tag is having three attributes called size, color, and face to customize your fonts. To change any of the font attributes at any time within your webpage, simply use the <font> tag.

How do I change the default text color in HTML? ›

The <basefont> tag was used in HTML 4 to specify a default text-color, font-size or font-family for all the text in an HTML document.

How do I color all text in CSS? ›

Simply add the appropriate CSS selector and define the color property with the value you want. For example, say you want to change the color of all paragraphs on your site to navy. Then you'd add p {color: #000080; } to the head section of your HTML file.

How do I change the color of text and underline in HTML? ›

Change the underline color by typing a { text-decoration: none; border-bottom:1px solid red; }. Replace solid red with another color.

How do I manage text align in HTML? ›

// Syntax text-align: start; text-align: end; text-align: left; text-align: right; text-align: center; text-align: justify; If you want to align the entire text on your web page, you can apply this property to any tag containing the text, such as the div tag, heading, paragraph, or body tag.

Top Articles
Latest Posts
Article information

Author: Rueben Jacobs

Last Updated:

Views: 5324

Rating: 4.7 / 5 (57 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Rueben Jacobs

Birthday: 1999-03-14

Address: 951 Caterina Walk, Schambergerside, CA 67667-0896

Phone: +6881806848632

Job: Internal Education Planner

Hobby: Candle making, Cabaret, Poi, Gambling, Rock climbing, Wood carving, Computer programming

Introduction: My name is Rueben Jacobs, I am a cooperative, beautiful, kind, comfortable, glamorous, open, magnificent person who loves writing and wants to share my knowledge and understanding with you.