Treehouse: Grow your CSS skills. Land your dream job.

Last updated on:

Simple and Nice Blockquote Styling

The blockquote displays in standards-compliant browsers with the "big quotes before" effect, and in IE with a thick left border and a light grey background.
Unlike other blockquote techniques, this style does not require a nested block-level element (like p). As such, it turns a paragraph into an inline-styled element to keep the content from dropping below the quote.

blockquote {
  background: #f9f9f9;
  border-left: 10px solid #ccc;
  margin: 1.5em 10px;
  padding: 0.5em 10px;
  quotes: "\201C""\201D""\2018""\2019";
}
blockquote:before {
  color: #ccc;
  content: open-quote;
  font-size: 4em;
  line-height: 0.1em;
  margin-right: 0.25em;
  vertical-align: -0.4em;
}
blockquote p {
  display: inline;
}

Example

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

Comments

  1. Dyllon
    Permalink to comment#

    the only thing i would like for this would be a closing quote at the end.

  2. Dyllon
    Permalink to comment#

    scratch that..

  3. Jared
    Permalink to comment#

    What will this look like?

  4. Dan Sensecall
    Permalink to comment#

    Thanks very much for this!

  5. Nipperkin
    Permalink to comment#

    Personally, I think that the use of the vertical line *and* the quotation mark is redundant, since they both signify the same thing.

  6. Dez
    Permalink to comment#

    This doesn’t seem to work in chrome/safari.

  7. Dez
    Permalink to comment#

    … If you want it to work in Safari/Chrome.

    blockquote:before {

    content:”\201C”;

    }

    blockquote:after {

    content:”\201D”;

    }

  8. Wolf
    Permalink to comment#

    Using multiple blockquotes one after another seems to result in the first instance having a double quote before but every subsequent instance having only a single quote before (in Firefox). Why would this be?

    • Efrain
      Permalink to comment#

      Having the same issue. How can I fix this?

      Thanks

    • Ivan
      Permalink to comment#

      Yep, had this same issue. I tried what the dude said in the above comment. It fixes the problem!

    • Andrew
      Permalink to comment#

      It looks like it’s because of the 3rd & 4th parameters in the quote attribute.
      From: http://www.w3schools.com/cssref/pr_gen_quotes.asp

      quote: string string string string
      Specifies which quotation marks to use. The first two values specifies the first level of quotation embedding, the next two values specifies the next level of quote embedding, etc

      Hence if you’re not closing quotes it’ll use the 3rd parameter.

      I changed it to quotes: "\201C""\201D"; and it fixed it for me.

      Cheers

  9. kathy
    Permalink to comment#

    what would the
    code for the closing quote be?

  10. kathy
    Permalink to comment#

    sorted

    blockquote:after {color:#B2AFCD;content:close-quote;font-size:4em;line-height:.1em;margin-right:.25em;vertical-align:-.4em;}

    just gotta paly with the spac a bit :)

  11. kathy
    Permalink to comment#

    ‘Scuse my appalling spelling!

    final

    blockquote:after {color:#B2AFCD;content:close-quote;font-size:4em;line-height:.1em;margin-left: .20em;vertical-align:-.4em;}

    Thanks for great tips Chris :)

  12. Charlie
    Permalink to comment#

    What’s the:

    quotes:"\201C""\201D""\2018""\2019";

    for on blockquote?
    You don’t seem to need it if you specify \201C and \201D on :before and :after.

    Am I missing something?

  13. Brad Czerniak
    Permalink to comment#

    Hey all, as the original snippet submitter, I just wanted to follow up and address some of the weaknesses mentioned in the comments. Here is some css that I think is an improvement:

    
    blockquote{background:#f9f9f9;border-left:1em solid #eee;margin:1.5em 1em;padding:.5em 1em;quotes:"\201C""\201D";}
           blockquote:before{color:#808080;content:open-quote;font-size:4em;line-height:.1em;margin-right:.25em;vertical-align:-.4em;}
           blockquote :first-child{display:inline;}
           blockquote :last-child{margin-bottom:0;}
    
    • Ren

      I was gonna mentioned some of the same changes as you (i.e. the first and last child), Brad, but then I noticed your comment. Good calls. I’d just add that it might be a good idea to set the :first-child to inline-block to preserve the bottom margin.

    • Emnem

      Inline blocking makes the opening quote display above and to the left of the first line. Kind of seeking an answer to this myself, since preserving inline styling on a multi-paragraph quote (without amending it to inline-block) makes the first paragraph lay right on top of the next one. Very funky positioning issues (at least in Fx32/33 Nightly).

  14. jenn
    Permalink to comment#

    This doesn’t seem to work in chrome.

  15. David Darnes
    Permalink to comment#

    Very useful reference! If anyone is wondering why only their first blockquote has the double quote marks but the following ones don’t, you just need to add:

    blockquote:after {
    content: no-close-quote;
    }

  16. Voytek
    Permalink to comment#

    Hi,

    How to add a box shadow ?
    Thanks

  17. Praveen Puglia
    Permalink to comment#

    Pretty easy and cool! Thanks Chris!

  18. Mesaber
    Permalink to comment#

    Thanks man, it helped me alot :)

  19. Derek

    Anyone know how to modify the css so that there is a space between paragraphs in a block quote? Thanks for any help.

  20. WindyLiu
    Permalink to comment#

    Pretty style!

  21. Eric B
    Permalink to comment#

    The demo page is a dead link!

  22. Sudeep B
    Permalink to comment#

    @css-trick @David Darnes

    Nice one.

  23. Don
    Permalink to comment#

    Greetings – some modifications to the code that makes it work for me :-)

    blockquote {
      margin: 1.5em 0 1.5em;
      padding: 0 1em 0 2.5em;
      position:relative;
    }
    blockquote:before
     {
      color: #ccc;
      content: "\201C";
      font-size: 5em;
      position:absolute;
      left:5px;
      top: 0.3em;
      line-height: 0.1em;
    }
    
    blockquote:after
     {
       color: #ccc;
      content: "\201D";
      font-size: 5em;
      position:absolute;
      right:3px;
      bottom: 0em;
      line-height: 0.1em;
    }
    

    The important bits – I have padding on both sides. Setting the blockquote element to position:relative means you can set the blockquote:before`` and blockquote:after to position:absolute, and then position the quote to using left, right, bottom and top

    • Rick
      Permalink to comment#

      Don, the text was overlapping the end quotation symbols on the right (FF v25).

      Changing the right-side padding from 1em to 2.5em fixes it.

      padding: 0 2.5em 0 2.5em

      Thanks everyone for this!

  24. Daniel
    Permalink to comment#

    Nice and clean! You’ve just missed a colon (:) here:
    blockquote p {
    display: inline;
    }

  25. Jacky Liang
    Permalink to comment#

    For the before element, the vertical-align prevented text from being selected. It took me a while to get rid of the bug, but I think it works now.

    display:inline-block;color:#FFF;height:25px;font-size:2.8em;line-height:80px;content:'\201F';letter-spacing:-2px;float:left;position:relative;right:8px

  26. Steven Fromm
    Permalink to comment#

    Is there a simpler way to make quotes attractive if you do not really understand the above CSS stuff. I fear it is beyond me.

    • Torsten
      Permalink to comment#

      You could style blockquotes to appear in italics, like this:

      blockquote {
      font-style: italic;
      }

  27. Abhimanyu
    Permalink to comment#

    What is the blockquote:before for?

  28. Karissa
    Permalink to comment#

    Thanks! I learned what I needed in the comments. It’s always bothered be that there was only the first quote and not two.

    I tweeked one of the above a little more and added purple to it.

    blockquote {
        background-color: #9786c6;
        border-left: 1em solid #5236a0;
        margin: 1.5em 0 1.5em;
        padding: 1em 1.5em 0 2.5em;
        position: relative;
    }
    blockquote:before {
      color: #392570;
      content: "\201C";
      font-size: 5em;
      position:absolute;
      left:5px;
      top: 0.6em;
      line-height: 0.1em;
    }
    
    blockquote:after {
       color: #392570;
      content: "\201D";
      font-size: 5em;
      position:absolute;
      right:3px;
      bottom: 0em;
      line-height: 0.1em;
    }      
    
    

    See how they turned out on http://meetkarissa.com/sleepphones .

  29. bob
    Permalink to comment#

    Have you tried selecting the text in that example in Chrome?

  30. Noemi
    Permalink to comment#

    Thank you for this tutorial! It’s just what I need.
    How can I make the commas bigger?

  31. Uday Khandelwal

    I have a doubt from the first post, I can’t get my text to be displayed inline.
    is blockquote p{
    display : inline;
    }

    for the

    text in the HTML.

    My HTML code is like

    “We are what we repeatedly do. Excellence, then, is not an act, but a habit.”- Aristotle

  32. Pawan
    Permalink to comment#

    Hello guys,

    Check this..

    Simple and Superb……..

    .tmls_text:after {
    color: #ccc;
    content: close-quote;
    font-size: 4em;
    line-height: 0.1em;
    margin-left: 0.25em;
    vertical-align: -0.4em;
    }

  33. One9ooh6
    Permalink to comment#

    Unfortunately this isn’t working in Internet Explorer.

Leave a Comment

Posting Code

We highly encourage you to post problematic HTML/CSS/JavaScript over on CodePen and include the link in your post. It's much easier to see, understand, and help with when you do that.

Markdown is supported, so you can write inline code like `<div>this</div>` or multiline blocks of code in in triple backtick fences like this:

```
<script>
  function example() {
    element.innerHTML = "<div>code</div>";
  }
</script>
```