The as_raw_html() function

Use a subset of the gtcars dataset to create a gt table. Add a header with tab_header() and then export the table as HTML code with inlined CSS styles using as_raw_html().

tab_html <-
  gtcars |>
  dplyr::select(mfr, model, msrp) |>
  dplyr::slice_head(n = 5) |>
  gt() |>
  tab_header(
    title = md("Data listing from **gtcars**"),
    subtitle = md("`gtcars` is an R dataset")
  ) |>
  as_raw_html()

What’s returned is a single-element vector containing the HTML for the table. It has only the <table>...</table> part so it’s not a complete HTML document but rather an HTML fragment.