HUGO

  • News
  • Docs
  • Themes
  • Showcase
  • Community
  • GitHub
gohugoio Star
  • About Hugo
    • Overview
    • What is Hugo
    • Hugo features
    • Static site generators
    • Hugo's security model
    • Hugo and the GDPR
    • License
  • Installation
    • Overview
    • macOS
    • Linux
    • Windows
    • BSD
  • Getting started
    • Overview
    • Quick start
    • Basic usage
    • Directory structure
    • Configuration
    • Configure markup
    • Glossary of terms
    • External learning resources
  • Quick reference
    • Overview
    • Emojis
    • Functions
    • Methods
    • Page collections
  • Content management
    • Overview
    • Organization
    • Page bundles
    • Content formats
    • Front matter
    • Build options
    • Page resources
    • Image processing
    • Shortcodes
    • Related content
    • Sections
    • Content types
    • Archetypes
    • Taxonomies
    • Summaries
    • Links and cross references
    • URL management
    • Menus
    • Static files
    • Table of contents
    • Comments
    • Multilingual
    • Markdown attributes
    • Syntax highlighting
    • Diagrams
    • Mathematics
  • Templates
    • Overview
    • Templating
    • Template lookup order
    • Base templates and blocks
    • Single page templates
    • List templates
    • Homepage template
    • Section templates
    • Taxonomy templates
    • Pagination
    • Content view templates
    • Partial templates
    • Shortcode templates
    • Menu templates
    • Data templates
    • RSS templates
    • Sitemap templates
    • Internal templates
    • Custom output formats
    • 404 page
    • Robots.txt
  • Functions
    • Overview
    • cast
    • collections
    • compare
    • crypto
    • data
    • debug
    • diagrams
    • encoding
    • fmt
    • global
    • go template
    • hugo
    • images
    • inflect
    • js
    • lang
    • math
    • openapi3
    • os
    • partials
    • path
    • reflect
    • resources
    • safe
    • strings
    • templates
    • time
    • transform
    • urls
  • Methods
    • Overview
    • Duration
    • Menu
    • Menu entry
    • Page
    • Pages
    • Resource
    • Shortcode
    • Site
    • Taxonomy
    • Time
  • Render hooks
    • Overview
    • Introduction
    • Code blocks
    • Headings
    • Images
    • Links
  • Hugo Modules
    • Overview
    • Configure Hugo modules
    • Use Hugo Modules
    • Theme components
  • Hugo Pipes
    • Overview
    • Introduction
    • Transpile Sass to CSS
    • PostCSS
    • PostProcess
    • JavaScript building
    • Babel
    • Asset minification
    • Concatenating assets
    • Fingerprinting and SRI hashing
    • Resource from string
    • Resource from template
  • CLI
  • Troubleshooting
    • Overview
    • Audit
    • Logging
    • Inspection
    • Deprecation
    • Performance
    • FAQs
  • Developer tools
    • Overview
    • Editor plugins
    • Front-ends
    • Search
    • Migrations
    • Other projects
  • Hosting and deployment
    • Overview
    • Hugo Deploy
    • Deploy with Rclone
    • Deploy with Rsync
    • Host on 21YunBox
    • Host on AWS Amplify
    • Host on Azure Static Web Apps
    • Host on Cloudflare Pages
    • Host on Firebase
    • Host on GitHub Pages
    • Host on GitLab Pages
    • Host on KeyCDN
    • Host on Netlify
    • Host on Render
  • Contribute
    • Overview
    • Development
    • Documentation
    • Themes
  • Maintenance
CONTENT MANAGEMENT

Static files

Files that get served statically (as-is, no modification) on the site root.

By default, the static/ directory in the site project is used for all static files (e.g. stylesheets, JavaScript, images). The static files are served on the site root path (eg. if you have the file static/image.png you can access it using http://{server-url}/image.png, to include it in a document you can use ![Example image](/image.png) ).

Hugo can be configured to look into a different directory, or even multiple directories for such static files by configuring the staticDir parameter in the site configuration. All the files in all the static directories will form a union filesystem.

This union filesystem will be served from your site root. So a file <SITE PROJECT>/static/me.png will be accessible as <MY_BASEURL>/me.png.

Here’s an example of setting staticDir and staticDir2 for a multi-language site:

hugo.
     
languages:
  en:
    baseURL: https://example.org/
    languageName: English
    staticDir2: static_en
    title: In English
    weight: 2
  "no":
    baseURL: https://example.no
    languageName: Norsk
    staticDir:
    - staticDir_override
    - static_no
    title: På norsk
    weight: 1
staticDir:
- static1
- static2
staticDir = ['static1', 'static2']
[languages]
  [languages.en]
    baseURL = 'https://example.org/'
    languageName = 'English'
    staticDir2 = 'static_en'
    title = 'In English'
    weight = 2
  [languages.no]
    baseURL = 'https://example.no'
    languageName = 'Norsk'
    staticDir = ['staticDir_override', 'static_no']
    title = 'På norsk'
    weight = 1
{
   "languages": {
      "en": {
         "baseURL": "https://example.org/",
         "languageName": "English",
         "staticDir2": "static_en",
         "title": "In English",
         "weight": 2
      },
      "no": {
         "baseURL": "https://example.no",
         "languageName": "Norsk",
         "staticDir": [
            "staticDir_override",
            "static_no"
         ],
         "title": "På norsk",
         "weight": 1
      }
   },
   "staticDir": [
      "static1",
      "static2"
   ]
}

In the above, with no theme used:

  • The English site will get its static files as a union of “static1”, “static2” and “static_en”. On file duplicates, the right-most version will win.
  • The Norwegian site will get its static files as a union of “staticDir_override” and “static_no”.
Note 1
The 2 (can be a number between 0 and 10) in staticDir2 is added to tell Hugo that you want to add this directory to the global set of static directories defined using staticDir. Using staticDir on the language level would replace the global value (as can be seen in the Norwegian site case).
Note 2
The example above is a multihost setup. In a regular setup, all the static directories will be available to all sites.

See also

  • Directory structure

On this page

Last updated: November 4, 2023: Miscellaneous updates (80b2241f)
Improve this page
By the Hugo Authors
Hugo Logo
  • File an Issue
  • Get Help
  • @GoHugoIO
  • @spf13
  • @bepsays

Netlify badge

 

Hugo Sponsors

 

The Hugo logos are copyright © Steve Francia 2013–2024.

The Hugo Gopher is based on an original work by Renée French.

  • News
  • Docs
  • Themes
  • Showcase
  • Community
  • GitHub
  • About Hugo
  • Installation
  • Getting started
  • Quick reference
  • Content management
  • Templates
  • Functions
  • Methods
  • Render hooks
  • Hugo Modules
  • Hugo Pipes
  • CLI
  • Troubleshooting
  • Developer tools
  • Hosting and deployment
  • Contribute
  • Maintenance