# Styles

React Native allows you to style components using a subset of CSS properties as inline styles. For layout only the flexbox module and absolute positioning is available. The [style properties](https://facebook.github.io/react-native/releases/next/docs/style.html#supported-properties) are split into five categories:

1. View Properties
2. Image Properties
3. Text Properties
4. Flex Properties
5. Transform Properties

## Usage for Static Styles

Use `StyleSheet.create` to construct styles and define them at the end of the file. This ensures that the values are immutable and they are only created once for the application and not on every render.

```javascript
var RedBox = ({ children }) => {
  return (
    <View style={ styles.base }>
      { children }
    </View>
  );
};

const styles = StyleSheet.create({
  base: {
    backgroundColor: '#222222',
    color: '#fff',
  },
  active: {
    backgroundColor: '#85144b',
    color: '#B10DC9'
  },
});
```

You can also compose styles

```javascript
// As an array
<View style={[styles.base, styles.background]} />
// or conditionally
<View style={[styles.base, this.state.active && styles.active]} />
```

## Usage for Dynamic Styles

Dynamic styles can be created as objects in the render. However, the official documentation recommends that you avoid this:

> Finally, if you really have to, you can also create style objects in render, but they are highly discouraged. Put them last in the array definition.

```javascript
var RedBox = ({ children, width }) => {
  return (
    <View style={[styles.base, {
      width: this.state.width,
    }]}>
      { children }
    </View>
  );
};

const styles = StyleSheet.create({
  base: {
    backgroundColor: '#222222',
    color: '#fff',
  },
  active: {
    backgroundColor: '#85144b',
    color: '#B10DC9'
  },
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rangle-io.gitbook.io/react-native-workshop/index-1/styles.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
