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 create CSS triangles or arrow heads

    on Mar 26, 2016

    CSS triangles (arrow heads) in various directions (up, down, left, right) can be created using a combination of thick CSS borders (visible and transparent) on a 0 size div element. Follow the following steps to create triangles using CSS.

    1. First we’ll create a 0 width/height div with thick borders of different colors. This way it will be easier to visualize that we can take a combination of these 4 borders and create desired triangle.
      <style type="text/css" media="screen">
      .onlyborders {
        width:0; height:0;
        border-top: 30px solid red;
        border-right: 30px solid blue;
        border-bottom: 30px solid green;
        border-left: 30px solid orange;
      }
      </style>
      
      <p>All 4 borders present</p>
      <div class="onlyborders"></div>
      refresh done
      try it online

    2. Now create a 0 width/height div with three borders (left, right and bottom). This will also help us visualize how borders appear when only three of them are present.
      <p>Only left, right and bottom borders present</p>
      <style type="text/css" media="screen">
      .onlyborders {
        width:0; height:0;
        border-right: 30px solid blue;
        border-bottom: 30px solid green;
        border-left: 30px solid orange;
      }
      </style>
      
      <div class="onlyborders"></div>
      refresh done
      try it online

    3. To create a triangle (say pointing up), we need to have bottom border visible and left and right border transparent. Similarly we can create other triangles.
      <style type="text/css" media="screen">
      .up {
        width:0; height:0;
        border-bottom: 30px solid green;
        border-right: 30px solid transparent;
        border-left: 30px solid transparent;
      }
      .down {
        width:0; height:0;
        border-top: 30px solid green;
        border-right: 30px solid transparent;
        border-left: 30px solid transparent;
      }
      .left {
        width:0; height:0;
        border-right: 30px solid green;
        border-top: 30px solid transparent;
        border-bottom: 30px solid transparent;
      }
      .right {
        width:0; height:0;
        border-left: 30px solid green;
        border-top: 30px solid transparent;
        border-bottom: 30px solid transparent;
      }
      </style>
      up<div class="up"></div><hr/>
      down<div class="down"></div><hr/>
      left<div class="left"></div><hr/>
      right<div class="right"></div><hr/>
      refresh done
      try it online

    Suggested posts:

    1. CSS border-width – set element border width of four sides
    2. HTML ol tag
    3. Css :first-child selector – first child element
    4. Install nginx and php in docker ubuntu container
    5. CSS list-style – shorthand for list marker type, image and position
    6. jQuery – get checkbox value and checked state
    7. CSS – align multiple divs horizontally
    8. How to use nc (netcat) to print headers sent by a browser
    Share this article: share on facebook share on linkedin tweet this submit to reddit
    Posted in Tutorials | Tagged CSS, CSS cookbook, Tutorials, Web Development
    • 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