The opt_css() function

Let’s use the exibble dataset to create a simple, two-column gt table (keeping only the num and currency columns). Through use of the opt_css() function, we can insert CSS rulesets as as string. We need to ensure that the table ID is set explicitly (we’ve done so here with the ID value of "one", setting it in the gt() function).

exibble |>
  dplyr::select(num, currency) |>
  gt(id = "one") |>
  fmt_currency(
    columns = currency,
    currency = "HKD"
  ) |>
  fmt_scientific(columns = num) |>
  opt_css(
    css = "
    #one .gt_table {
      background-color: skyblue;
    }
    #one .gt_row {
      padding: 20px 30px;
    }
    #one .gt_col_heading {
      text-align: center !important;
    }
    "
  )
num currency
1.11 × 10−1 HK$49.95
2.22 HK$17.95
3.33 × 101 HK$1.39
4.44 × 102 HK$65,100.00
5.55 × 103 HK$1,325.81
NA HK$13.26
7.77 × 105 NA
8.88 × 106 HK$0.44