| 1 |
# Sphinx Favicon |
| 2 |
|
| 3 |
[](https://opensource.org/licenses/MIT) |
| 4 |
[](https://github.com/psf/black) |
| 5 |
[](https://pypi.org/project/sphinx-favicon/) |
| 6 |
[](https://pypi.org/project/sphinx-favicon/) |
| 7 |
[](https://github.com/tcmetzger/sphinx-favicon/actions/workflows/basic-ci.yml) |
| 8 |
[](https://readthedocs.org/projects/sphinx-favicon/) |
| 9 |
|
| 10 |
> **Note: Updating from Version 0.2 to Version 1.x and beyond** |
| 11 |
> |
| 12 |
> Between v0.2 and v1.0, the module name of the extension changed to better conform with Python standards. Please update the name used in the extension list of your `conf.py` from `sphinx-favicon` to `sphinx_favicon`! |
| 13 |
|
| 14 |
**A Sphinx extension to add custom favicons** |
| 15 |
|
| 16 |
With Sphinx Favicon, you can add custom favicons to your Sphinx html |
| 17 |
documentation quickly and easily. |
| 18 |
|
| 19 |
You can define favicons directly in your `conf.py`, with different `rel` |
| 20 |
attributes such as [`"icon"`](https://html.spec.whatwg.org/multipage/links.html#rel-icon) |
| 21 |
or [`"apple-touch-icon"`](https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html) and |
| 22 |
any favicon size. |
| 23 |
|
| 24 |
The Sphinx Favicon extension gives you more flexibility than the [standard |
| 25 |
`favicon.ico` supported by Sphinx](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_favicon). It provides a quick and easy way to add the most |
| 26 |
important favicon formats for different browsers and devices. |
| 27 |
|
| 28 |
## Installation |
| 29 |
|
| 30 |
Use ``pip`` to install Sphinx Favicon in your environment: |
| 31 |
|
| 32 |
```sh |
| 33 |
pip install sphinx-favicon |
| 34 |
``` |
| 35 |
|
| 36 |
## Usage |
| 37 |
|
| 38 |
After installing **sphinx-favicon**, add it to your `conf.py` extension list: |
| 39 |
|
| 40 |
```python |
| 41 |
extensions = ["sphinx_favicon"] |
| 42 |
``` |
| 43 |
|
| 44 |
Then configure the favicon links using the `favicons` parameter (`html_static_path` is mandatory if you use relative path): |
| 45 |
|
| 46 |
```python |
| 47 |
html_static_path = ["_static"] |
| 48 |
|
| 49 |
favicons = [ |
| 50 |
{"href": "icon.svg"}, # => use `_static/icon.svg` |
| 51 |
{"href": "https://secure.example.com/favicon/favicon-16x16.png"}, |
| 52 |
{"href": "https://secure.example.com/favicon/favicon-32x32.png"}, |
| 53 |
{ |
| 54 |
"rel": "apple-touch-icon", |
| 55 |
"href": "https://secure.example.com/favicon/apple-touch-icon-180x180.png", |
| 56 |
}, |
| 57 |
] |
| 58 |
``` |
| 59 |
|
| 60 |
Based on this configuration, Sphinx will include the following favicon information in the HTML `<head>` element: |
| 61 |
|
| 62 |
```html |
| 63 |
<link rel="icon" href="_static/icon.svg" type="image/svg+xml"> |
| 64 |
<link rel="icon" href="https://secure.example.com/favicon/favicon-16x16.png" sizes="16x16" type="image/png"> |
| 65 |
<link rel="icon" href="https://secure.example.com/favicon/favicon-32x32.png" sizes="32x32" type="image/png"> |
| 66 |
<link rel="apple-touch-icon" href="https://secure.example.com/favicon/apple-touch-icon-180x180.png" sizes="180x180" type="image/png"> |
| 67 |
``` |
| 68 |
|
| 69 |
For more details and more advanced usage, please see the |
| 70 |
[documentation](https://sphinx-favicon.readthedocs.io). |
| 71 |
|
| 72 |
## Contribution |
| 73 |
|
| 74 |
Contributions of any kind are welcome. Please see the |
| 75 |
[contribution](https://sphinx-favicon.readthedocs.io/en/latest/contribute.html) section of |
| 76 |
our documentation for more information. |