1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
---
id: 'Code block'
section: components
cssPrefix: pf-v6-c-code-block
---## Examples
### Basic
```html
<div class="pf-v6-c-code-block">
<div class="pf-v6-c-code-block__header">
<div class="pf-v6-c-code-block__actions">
<div class="pf-v6-c-code-block__actions-item">
<button
class="pf-v6-c-button pf-m-plain"
type="button"
aria-label="Copy to clipboard basic example code content"
>
<span class="pf-v6-c-button__icon">
<i class="fas fa-copy" aria-hidden="true"></i>
</span>
</button>
</div>
<div class="pf-v6-c-code-block__actions-item">
<button
class="pf-v6-c-button pf-m-plain"
type="button"
aria-label="Run basic example code in Web Terminal"
>
<span class="pf-v6-c-button__icon">
<i class="fas fa-play" aria-hidden="true"></i>
</span>
</button>
</div>
</div>
</div>
<div class="pf-v6-c-code-block__content">
<pre class="pf-v6-c-code-block__pre"><code class="pf-v6-c-code-block__code">apiVersion: helm.openshift.io/v1beta1/
kind: HelmChartRepository
metadata:
name: azure-sample-repo
spec:
connectionConfig:
url: https://raw.githubusercontent.com/Azure-Samples/helm-charts/master/docs</code>
</pre>
</div>
</div>
```
### Expandable
```html
<div class="pf-v6-c-code-block">
<div class="pf-v6-c-code-block__header">
<div class="pf-v6-c-code-block__actions">
<div class="pf-v6-c-code-block__actions-item">
<button
class="pf-v6-c-button pf-m-plain"
type="button"
aria-label="Copy to clipboard expandable example code content"
>
<span class="pf-v6-c-button__icon">
<i class="fas fa-copy" aria-hidden="true"></i>
</span>
</button>
</div>
<div class="pf-v6-c-code-block__actions-item">
<button
class="pf-v6-c-button pf-m-plain"
type="button"
aria-label="Run expandable example code in Web Terminal"
>
<span class="pf-v6-c-button__icon">
<i class="fas fa-play" aria-hidden="true"></i>
</span>
</button>
</div>
</div>
</div>
<div class="pf-v6-c-code-block__content">
<pre class="pf-v6-c-code-block__pre"><code class="pf-v6-c-code-block__code">apiVersion: helm.openshift.io/v1beta1/
kind: HelmChartRepository
metadata:
name: azure-sample-repo<div
class="pf-v6-c-expandable-section pf-m-detached"
><div
class="pf-v6-c-expandable-section__content"
hidden
id="code-block-expandable-content"
role="region"
aria-labelledby="code-block-expandable-toggle"
>
spec:
connectionConfig:
url: https://raw.githubusercontent.com/Azure-Samples/helm-charts/master/docs</div>
</div>
</code>
</pre>
<div class="pf-v6-c-expandable-section pf-m-detached">
<div class="pf-v6-c-expandable-section__toggle">
<button
class="pf-v6-c-button pf-m-link"
id="code-block-expandable-toggle"
type="button"
aria-expanded="false"
aria-controls="code-block-expandable-content"
>
<span class="pf-v6-c-button__icon pf-m-start">
<span
class="pf-v6-c-expandable-section__toggle-icon pf-m-expand-top"
>
<i class="fas fa-angle-right" aria-hidden="true"></i>
</span>
</span>
<span class="pf-v6-c-button__text">Show more</span>
</button>
</div>
</div>
</div>
</div>
```
### Expandable expanded
```html
<div class="pf-v6-c-code-block">
<div class="pf-v6-c-code-block__header">
<div class="pf-v6-c-code-block__actions">
<div class="pf-v6-c-code-block__actions-item">
<button
class="pf-v6-c-button pf-m-plain"
type="button"
aria-label="Copy to clipboard expandable expanded example code content"
>
<span class="pf-v6-c-button__icon">
<i class="fas fa-copy" aria-hidden="true"></i>
</span>
</button>
</div>
<div class="pf-v6-c-code-block__actions-item">
<button
class="pf-v6-c-button pf-m-plain"
type="button"
aria-label="Run expandable expanded example code in Web Terminal"
>
<span class="pf-v6-c-button__icon">
<i class="fas fa-play" aria-hidden="true"></i>
</span>
</button>
</div>
</div>
</div>
<div class="pf-v6-c-code-block__content">
<pre class="pf-v6-c-code-block__pre"><code class="pf-v6-c-code-block__code">apiVersion: helm.openshift.io/v1beta1/
kind: HelmChartRepository
metadata:
name: azure-sample-repo<div
class="pf-v6-c-expandable-section pf-m-expanded pf-m-detached"
><div
class="pf-v6-c-expandable-section__content"
id="code-block-expandable-expanded-content"
role="region"
aria-labelledby="code-block-expandable-expanded-toggle"
>
spec:
connectionConfig:
url: https://raw.githubusercontent.com/Azure-Samples/helm-charts/master/docs</div>
</div>
</code>
</pre>
<div class="pf-v6-c-expandable-section pf-m-expanded pf-m-detached">
<div class="pf-v6-c-expandable-section__toggle">
<button
class="pf-v6-c-button pf-m-link"
id="code-block-expandable-expanded-toggle"
type="button"
aria-expanded="true"
aria-controls="code-block-expandable-expanded-content"
>
<span class="pf-v6-c-button__icon pf-m-start">
<span
class="pf-v6-c-expandable-section__toggle-icon pf-m-expand-top"
>
<i class="fas fa-angle-right" aria-hidden="true"></i>
</span>
</span>
<span class="pf-v6-c-button__text">Show less</span>
</button>
</div>
</div>
</div>
</div>
```
## Documentation
### Usage
| Class | Applied to | Outcome |
| -- | -- | -- |
| `.pf-v6-c-code-block` | `<div>` | Initiates the code block component. **Required** |
| `.pf-v6-c-code-block__header` | `<div>` | Initiates the code block header. |
| `.pf-v6-c-code-block__actions` | `<div>` | Initiates the code block actions. |
| `.pf-v6-c-code-block__actions-item` | `<div>` | Initiates a code block action item. |
| `.pf-v6-c-code-block__content` | `<div>` | Initiates the code block content. **Required** |
| `.pf-v6-c-code-block__pre` | `<pre>` | Initiates the code block `<pre>` element. **Required** |
| `.pf-v6-c-code-block__code` | `<code>` | Initiates the code block `<code>` element. **Required** |
|