banner



How To Add A Background Color In Html

  1. one

    Decide the groundwork color y'all want to use. HTML colors are dictated by codes on a per-shade ground. You lot tin utilise the costless W3Schools HTML color picker to find the code(southward) for the color(s) you desire to use:

    • Go to https://world wide web.w3schools.com/colors/colors_picker.asp in your computer'southward spider web browser.
    • Click a base color you lot'd like to use in the "Pick a Colour" section.
    • Select a shade on the right side of the folio.
    • Write down the numeric code to the correct of the shade.
  2. 2

    Open your HTML file in your favorite text editor. As of HTML5, the <bgcolor> HTML aspect is no longer supported. Background color, along with all other style aspects of your page, should be handled using CSS.[i]

    • You tin can utilise Notepad++ or Notepad on a Windows calculator, while Mac users can edit with TextEdit or BBEdit.

    Advertisement

  3. iii

    Add the "html" header to your document. All of the manner information for your folio (including the background color) should be coded between the <way></fashion> tags:

                                                      <!                        DOCTYPE                        html                        >                        <                        html                        >                        <                        head                        >                        <                        style                        >                        </                        mode                        >                        </                        head                        >                        </                        html                        >                      
  4. 4

    Create a blank line between the "style" tags. You should have a line on which you tin can add information below the <manner> tag and above the </style> tag.

  5. 5

    Add the "body" element. Type the following in between the <style></style> tags:

    • Anything you lot practise to the "trunk" chemical element in CSS volition affect the unabridged page.
    • Skip this step if you desire to create a gradient.

    Advertisement

  1. 1

    Find your document's "html" header. Information technology should be near the top of the document.

  2. two

    Add the "groundwork-colour" property to the "trunk" chemical element. Type background-color: between the body brackets. You should at present have the following "body" element:

                                                      body                        {                        background-colour                        :                        }                      
    • In this context, only 1 spelling of "color" volition piece of work; you can't use "colour" here.
  3. 3

    Add together your desired groundwork color to the "background-color" holding. Type your selected colour's numeric code followed past a semicolon side by side to the "background-color:" chemical element to do and so. For example, to ready your page'due south background to pink, you would have the post-obit:

                                                      body                        {                        background-color                        :                        #d24dff                        ;                        }                      
  4. 4

    Review your "fashion" information. At this point, your HTML document'southward header should resemble the following:

                                                      <!                        DOCTYPE                        html                        >                        <                        html                        >                        <                        head                        >                        <                        style                        >                        torso                        {                        background-color                        :                        #d24dff                        }                        </                        style                        >                        </                        head                        >                        </                        html                        >                      
  5. 5

    Use "background-color" to apply groundwork colors to other elements. Merely as yous set it in the trunk element, you can use "groundwork-color" to define the backgrounds of other elements such every bit headers, paragraphs, and so on. For example, to apply a background color to a main header (<h1>) or a paragraph (<p>), you would have something resembling the following lawmaking:[two]

                                                      <!                        DOCTYPE                        html                        >                        <                        html                        >                        <                        head                        >                        <                        style                        >                        body                        {                        background-color                        :                        #93B874                        ;                        }                        h1                        {                        background-color                        :                        #00b33c                        ;                        }                        p                        {                        background-color                        :                        #FFFFFF                        );                        }                        </                        mode                        >                        </                        caput                        >                        <                        body                        >                        <                        h1                        >                        Header                        with                        Green                        Background                        </                        h1                        >                        <                        p                        >                        Paragraph                        with                        white                        background                        </                        p                        >                        </                        body                        >                        </                        html                        >                      

    Advert

  1. 1

    Notice your document's "html" header. It should be near the pinnacle of the document.

  2. 2

    Empathise the bones syntax of this process. When making a gradient, there are two pieces of data you'll need: the starting point/angle, and the colors that the gradient will transition between. You can select multiple colors to have the gradient motion between all of them, and y'all can set a direction or angle for the gradient.[3]

                                                      background                        :                        linear-gradient                        (                        direction                        /                        angle                        ,                        color1                        ,                        color2                        ,                        color3                        ,                        etc                        .);                      
  3. three

    Make a vertical gradient. If you lot don't specify the direction, the slope will get from top to bottom. To create your gradient, add the following code betwixt the <way></way> tags:

                                                      html                        {                        min-elevation                        :                        100                        %                        ;                        }                        body                        {                        background                        :                        -webkit-                        linear-gradient                        (                        #93B874                        ,                        #C9DCB9                        );                        groundwork                        :                        -o-                        linear-gradient                        (                        #93B874                        ,                        #C9DCB9                        );                        background                        :                        -moz-                        linear-gradient                        (                        #93B874                        ,                        #C9DCB9                        );                        background                        :                        linear-gradient                        (                        #93B874                        ,                        #C9DCB9                        );                        groundwork-color                        :                        #93B874                        ;                        }                      
    • Dissimilar browsers take different implementations of the slope function, and so you'll have to include several versions of the code.
  4. four

    Brand a directional slope. If you'd rather create a slope that isn't strictly vertical, you tin add together direction to the gradient in guild to alter the style the color shift appears. Exercise so past typing the following in between the <mode></style> tags:[iv]

                                                      html                        {                        min-superlative                        :                        100                        %                        ;                        }                        torso                        {                        background                        :                        -webkit-                        linear-gradient                        (                        left                        ,                        #93B874                        ,                        #C9DCB9                        );                        background                        :                        -o-                        linear-slope                        (                        right                        ,                        #93B874                        ,                        #C9DCB9                        );                        groundwork                        :                        -moz-                        linear-slope                        (                        right                        ,                        #93B874                        ,                        #C9DCB9                        );                        background                        :                        linear-gradient                        (                        to                        right                        ,                        #93B874                        ,                        #C9DCB9                        );                        groundwork-color                        :                        #93B874                        ;                        }                      
    • You can play around with the "left" and "right" tags to experiment with dissimilar directions for your gradient.
  5. v

    Use other backdrop to conform the slope. There's a lot more than that you lot can exercise with gradients.

    • For example, not only can yous add more than two colors, you tin can also put a percentage after each 1. This volition allow you to fix how much spacing yous want each color segment to have. Here's a sample slope that uses this principle:
                                                          background                          :                          linear-slope                          (                          #                          93B874                          10                          %,                          #                          C9DCB9                          lxx                          %,                          #                          000000                          90                          %);                        
  6. half dozen

    Add transparency to your colors. This will make the color fade. Use the same color to fade from the color to naught. You'll need to use the rgba() function to define the color. The ending value determines the transparency: 0 for solid and one for transparent.

                                                      groundwork                        :                        linear-gradient                        (                        to                        correct                        ,                        rgba                        (                        147                        ,                        184                        ,                        116                        ,                        0                        ),                        rgba                        (                        147                        ,                        184                        ,                        116                        ,                        1                        ));                      
  7. seven

    Review your completed code. The code to create a color gradient every bit your website's background will look something like this:

                                                      <!                        DOCTYPE                        html                        >                        <                        html                        >                        <                        head                        >                        <                        style                        >                        html                        {                        min-peak                        :                        100                        %                        ;                        }                        body                        {                        background                        :                        -webkit-                        linear-gradient                        (                        left                        ,                        #93B874                        ,                        #C9DCB9                        );                        background                        :                        -o-                        linear-gradient                        (                        right                        ,                        #93B874                        ,                        #C9DCB9                        );                        background                        :                        -moz-                        linear-slope                        (                        right                        ,                        #93B874                        ,                        #C9DCB9                        );                        background                        :                        linear-gradient                        (                        to                        correct                        ,                        #93B874                        ,                        #C9DCB9                        );                        background-colour                        :                        #93B874                        ;                        }                        </                        mode                        >                        </                        head                        >                        <                        body                        >                        </                        body                        >                        </                        html                        >                      

    Advertisement

  1. one

    Detect your document'south "html" header. It should be near the top of the document.

  2. 2

    Add the animation property to the "body" element. Type the following into the space below the "body {" bracket and above the closing bracket:[five]

                                                      -webkit-animation                        :                        colorchange                        60s                        infinite                        ;                        animation                        :                        colorchange                        60s                        infinite                        ;                      
    • The top line of text is for Chromium-based browsers while the bottom line of text is for other browsers.
  3. 3

    Add your colors to the blitheness. At present you'll use the @keyframes rule to set the background colors through which yous'll cycle, likewise as the length of fourth dimension each color will announced on the page. Again, you'll demand separate entries for the unlike sets of browsers. Enter the following lines of code beneath the closed "trunk" bracket:[vi]

                                                      @                        -webkit-keyframes                        colorchange                        {                        0                        %                        {                        background                        :                        #33FFF3                        ;}                        25                        %                        {                        background                        :                        #78281F                        ;}                        50                        %                        {                        background                        :                        #117A65                        ;}                        75                        %                        {                        background                        :                        #DC7633                        ;}                        100                        %                        {                        background                        :                        #9B59B6                        ;}                        }                        @                        keyframes                        colorchange                        {                        0                        %                        {                        background                        :                        #33FFF3                        ;}                        25                        %                        {                        background                        :                        #78281F                        ;}                        fifty                        %                        {                        background                        :                        #117A65                        ;}                        75                        %                        {                        background                        :                        #DC7633                        ;}                        100                        %                        {                        background                        :                        #9B59B6                        ;}                        }                      
    • Notation that the 2 rules (@-webkit-keyframes and @keyframes have the same background colors and percentages. You lot'll want these to stay uniform so the experience is the same on all browsers.
    • The percentages (0%, 25%, etc) are of the total animation length (60s). When the page loads, the background will be the color ready at 0% (#33FFF3). Once the blitheness has played for 25% of of 60 seconds, the background will turn to #7821F, and so on.
    • You can modify the times and colors to fit your desired result.
  4. 4

    Review your code. Your entire code for the changing background color should resemble the post-obit:

                                                      <!                        DOCTYPE                        html                        >                        <                        html                        >                        <                        head                        >                        <                        style                        >                        body                        {                        -webkit-                        animation                        :                        colorchange                        60                        southward                        infinite                        ;                        animation                        :                        colorchange                        60                        south                        space                        ;                        }                        @                        -webkit-keyframes                        colorchange                        {                        0                        %                        {                        groundwork                        :                        #33FFF3                        ;}                        25                        %                        {                        background                        :                        #78281F                        ;}                        50                        %                        {                        background                        :                        #117A65                        ;}                        75                        %                        {                        background                        :                        #DC7633                        ;}                        100                        %                        {                        background                        :                        #9B59B6                        ;}                        }                        @                        keyframes                        colorchange                        {                        0                        %                        {                        background                        :                        #33FFF3                        ;}                        25                        %                        {                        background                        :                        #78281F                        ;}                        50                        %                        {                        groundwork                        :                        #117A65                        ;}                        75                        %                        {                        background                        :                        #DC7633                        ;}                        100                        %                        {                        background                        :                        #9B59B6                        ;}                        }                        </                        fashion                        >                        </                        head                        >                        <                        trunk                        >                        </                        body                        >                        </                        html                        >                      

    Advertisement

Add New Question

  • Question

    How do I set a groundwork color for a specific width?

    Community Answer

    Utilize the background-size holding inside of the "body" element. For case, "background-size: 300px 150px" makes the background 300 pixels wide and 150 pixels loftier.

  • Question

    It does not work. What tin can I do?

    UsernameHere11

    UsernameHere11

    Community Answer

    To arrive black, effort: torso { background-color: #190707}

  • Question

    What is the correct HTML for adding a groundwork color?

    Community Answer

    My text goes here! Replace the html code above with your text and selected your preferred color.

  • Question

    How do I underline my text?

    Pulasthi Udugamasooriya

    Pulasthi Udugamasooriya

    Community Answer

    Use the {{kbd|}} and {{kbd|}} tags effectually the text to be underlined, like so: {{kbd|My Heading}}

  • Question

    How do I change the groundwork color in my electronic mail account?

    Community Answer

    Go to Settings (not account settings), so press "Themes" or "Change Groundwork".

  • Question

    How do I apply more than 2 colors on my website?

    Community Answer

    Use the slope function provided above and put the 2 dissimilar colors at 50%. For case: background: -webkit-linear-slope(left, blue 50%, black 50%);.

  • Question

    Backgrounds within backgrounds poss? Folio has all-over groundwork color. How to add responsive padded background of slightly darker colour behind just text column?

    CageyCat

    You are talking almost a double border page. Look in Google for double border templates. Some come with the coding to make it, then all you lot need to do is put in the filename of your images.

  • Question

    How do I modify simply a small section of the background to a specific color?

    CageyCat

    Yous'd have to specify the section, commencement. Usually that's washed in external css, or in-line css.

  • Question

    How can I add CSS to my simple html web design? Do I have to open up another notepad or join the styling to my HTML?

    CageyCat

    If you want the CSS to control all pages, yep, you lot'd put it into its own file with CSS as the file extension. You'd then link the CSS file to your pages (in the coding). If yous want it on one folio, or just certain styling, y'all'd put the CSS in the coding.

  • Question

    Should I put this under the images in my HTML website?

    CageyCat

    Make a folder chosen images. Put all images used on your website (for the page itself) into that folder. But let's say y'all take pages about Canada and images specific to that country. Yous could brand a carve up folder chosen images-ca . Helps to be organized.

Show more than answers

Enquire a Question

200 characters left

Include your e-mail address to get a message when this question is answered.

Submit

Advertisement

  • If you want to use basic colors within your HTML lawmaking, you lot tin can blazon the colors' names without the pound sign (#) instead of using an HTML color lawmaking. For example: to create an orange background, you would type in background-color: orangish; here.

Advertizing

  • Make sure yous test any changes to your website before publishing them online.

Ad

Near This Commodity

Commodity Summary X

ane. Open the file.
ii. Find or insert the <style> </style> tags.
3. Add the body element.
four. Add the background-colour holding.
five. Insert the color code followed by a semicolon.

Did this summary help you?

Thank you to all authors for creating a folio that has been read ane,444,818 times.

Is this article up to date?

How To Add A Background Color In Html,

Source: https://www.wikihow.com/Set-Background-Color-in-HTML

Posted by: hobgoodplas1968.blogspot.com

0 Response to "How To Add A Background Color In Html"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel