Search code examples
pug

How can I add a style tag in the header with jade/pug?


I want something like this:

html
  head
    style(type="text/css")
      table {
        width: 100%
      }
  body
    table

But can't find the right incantation. This results in an "unexpected text" error. I tried escaping the css with a |, to no avail; and the best I've achieved so far is getting a table tag rendered in the header :(

Is it possible to do this with jade/pug?


Solution

  • Yes, you can add arbitrary text to any tag by suffixing it with a dot:

    style(type="text/css").
      table {
        width: 100%
      }
    

    In the documentation: https://pugjs.org/language/plain-text.html#recommended-solutions