InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

CSS

    CSS selectors

    • CSS selectors

    CSS properties

    • CSS properties

    CSS cookbooks

    • !important annotation
    • Align div in center horizontally
    • Align div in center vertically
    • Align multiple divs horizontally
    • Align text in center horizontally
    • CSS - drop cap effect
    • CSS - enlarge image on hover
    • CSS - round toggle switch using checkbox and label
    • CSS automatic table row numbering
    • CSS circle and oval
    • CSS clearfix - clear float automatically using ::after
    • CSS counters
    • CSS nested counters
    • CSS3 gradients
    • Create CSS triangles
    • First letter capital and bigger
    • How to display text on image using css
    • Install sass on Mac or Linux using ruby gem
    • Place a div in bottom right corner of browser
    • Test site css, javascript, html in old IEs
    • csslint
    • inherit value
    • initial value
    • inline-block and baseline alignment
    • margin collapsing
    • node-sass quick start tutorial on Linux and Mac
    • unset value
    • web typography
     
    • Home
    • > Tutorials
    • > CSS

    How to display text on image using css

    By admin | Last updated on Oct 8, 2016

    Css position can be used to place a text over an image. This can used to place some text like alpha or beta over a logo. Or if you want to create multiple logo for different countries, you can place country name as text on the image. Here are few approaches to achieve this using css.

    Text in div with absolute position

    Here is the code and the rendered outcome:

    <div style="position:relative">
    <img src="https://infoheap.com/img/demo_logo_infoheap_80.png" />
    <div style="position:absolute; left:300px;top:0px;color:#888;font-size:10px;">alpha</div>
    </div>
    refresh done
    try it online

    Few things to note:

    1. position:absolute renders the object relative to its containing block (nearest ancestor whose position is not static)
    2. position:absolute boxes are taken out of the normal flow (For detailed info see CSS 2.1 specification)

    Text in div with relative position css

    Here is the code and the rendered outcome:

    <div style="line-height:25px;">
    <img src="https://infoheap.com/img/demo_logo_infoheap_80.png" />
    <div style="position:relative; left:300px;top:-90px;color:#888;font-size:10px;">alpha</div>
    </div>
    refresh done
    try it online

    Few things to note:

    1. position:relative renders the object relative to its position in normal flow. Please note the negative value of property top.
    2. Since we don’t need a positioned parent, There is no need of having position:relative in the containing div.

    Text in div with background image css

    Here is the code and the rendered outcome:

    <div style="background:url(https://infoheap.com/img/demo_logo_infoheap_80.png) no-repeat;background-size:371px 80px;height:80px;width:371px">
    <div style="position:relative; left:300px;top:0px;color:#888;font-size:10px;">alpha</div>
    </div>
    refresh done
    try it online

    Few things to note:

    1. Here since image is container div’s background it does not come in normal flow.
    2. We had to give container div a width and height so that it is of the size of the img

    Suggested posts:

    1. CSS selector specificity
    2. Bash – how to run custom commands at script exit
    3. CSS – place a div in bottom right corner of browser
    4. CSS flexbox – display flex and inline-flex
    5. CSS text-indent – indent text in a block
    6. CSS text-decoration – underline, overline and strikeout text
    7. Running php eval on code with tags
    8. WordPress – write custom php log to separate file
    Share this article: share on facebook share on linkedin tweet this submit to reddit
    Posted in Tutorials | Tagged CSS, CSS cookbook, CSS layout, Tutorials
    • Browse content
    • Article Topics
    • Article archives
    • Contact Us
    Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

    Copyright © 2025 InfoHeap.

    Powered by WordPress