HTML Green Code
This page contains HTML code for coloring an element green. You can have green text, a green background, or a green border around an element.
Green Text
This example uses inline styles to set the text color to green (i.e. I use the style attribute against the HTML element).
In this case, I apply the styles against a <div> tag, but I could just have easily applied them against a <div> tag (for all text within that element) or even a <body> tag (for all text on the page).
| Source Code | Result |
|---|---|
|
Green text |
Here's the same thing, but this time using embedded styles.
| Source Code | Result |
|---|---|
|
Green text |
You could also place the CSS code into a external style sheet.
Green Background Color
You can set the background color of an element to green by using the CSS background-color property or the background shorthand property.
In this example, I've placed text inside a <div> tag, set its background color to green, and set its text color to orange.
| Source Code | Result |
|---|---|
|
Orange text, green background.
|
Green Border Color
In this example, I've added a green border around a <div> element.
| Source Code | Result |
|---|---|
|
I have a green border.
|
Green Color Codes
The above examples use green as the color value. I could just as easily used the hexadecimal or RGB color values and the result would've been the same.
Here are the various methods of specifying the color green in HTML.
| Source Code | Result |
|---|---|
|
Green text Green text (hexadecimal #008000) Green text (RGB value rgb(0,128,0)) |
Actually, the above examples don't use true green as in RGB ("Red Green Blue"). To do that, you need to use one of the following color codes:
| Source Code | Result |
|---|---|
|
Green text (hexadecimal #00ff00) Green text (hexadecimal shorthand #0f0) Green text (RGB value rgb(0,255,0)) |
Shades of Green
Here are some different shades of green that can be used instead of just plain old "green".